【发布时间】:2015-07-08 22:43:13
【问题描述】:
我已经用 C# 实现了 Nagasena 编码器:
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 女巫时遇到问题包含 或 &lt;&gt;:
<?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>&lt;</Text> 并从<Booo id="6001&lt;" /> 中删除&lt; - <Booo id="6001" /> 时,编码成功。但是在属性中没有使用 cdata 的可能性,并且当它包含 或 &lt;&gt; 时,它最终会出现错误。
我将调试 nagasena 库,但如果有人有一些有用的建议,我将不胜感激。
谢谢
【问题讨论】:
-
在调试了一些 nagasena 代码之后...我收到了内部 SaxException: {"reference to externally declared entity \"lt\" when document is declared Standalone"},所以我将属性 Standalone 更改为 no,并且它正在工作,但我不明白为什么......