我已经在C#中实现了长沙编码器:
public byte[] encodeEXI(byte[] inBytes)
{
MemoryStream outStream = new MemoryStream();
MemoryStream inStream = new MemoryStream(inBytes);
try
{
Transmogrifier transmogrifier = new Transmogrifier();
GrammarCache grammarCache = new GrammarCache((EXISchema)null, GrammarOptions.DEFAULT_OPTIONS);
transmogrifier.setGrammarCache(grammarCache, (SchemaId)null);
transmogrifier.OutputStream = outStream;
transmogrifier.AlignmentType = AlignmentType.compress;
transmogrifier.PreserveWhitespaces = false;
transmogrifier.PreserveLexicalValues = false;
transmogrifier.DeflateLevel = 1;
transmogrifier.ResolveExternalGeneralEntities = false;
Org.System.Xml.Sax.InputSource<Stream> iS = new Org.System.Xml.Sax.InputSource<Stream>(inStream);
transmogrifier.encode(iS);
outStream.Position = 0;
last = outStream.ToArray();
return outStream.ToArray();
}
catch (TransmogrifierException tex)
{
Console.WriteLine("Error in OpenExi_Library: " + tex);
return null;
}
finally
{
outStream.Close();
inStream.Close();
}
}我在编码包含<>或<>的简单有效的xml时遇到了问题:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<BPN>
<Booo id="6001<" />
<PoooPoo id="2600" />
<UserName>tomas</UserName>
<VooId>MYID</VooId>
<Text><</Text>
</BPN>它只是以TransmogrifierException结尾: Nagasena.Sax.TransmogrifierException: end of document is not expected。
我使用的是c#实现,所以我测试了java实现中的问题--在那里它工作得很好。所以我试着改变一些选项,但是都没有用。
当我用<Text><![CDATA[<]]></Text>替换<Text><</Text>,并从<Booo id="6001<" />中删除< - <Booo id="6001" />时,编码成功。但在属性中,不可能使用cdata,当它包含<>或<>时,它会以错误告终。
我打算调试nagasena库,但如果有人有一些有用的建议,我将不胜感激。
thx
发布于 2015-05-23 09:46:26
这个问题是由于在Nagasena中使用了AElfred XML解析器造成的。最新的nagasena使用的是Microsoft XML解析器,应该不会再出现这个问题。
https://stackoverflow.com/questions/26380247
复制相似问题