Nagasena/OpenExi:用<属性中



我已经在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&lt;" />
  <PoooPoo id="2600" />
  <UserName>tomas</UserName>
  <VooId>MYID</VooId>
  <Text>&lt;</Text>
</BPN>

它只是以TransmoverifierException结尾:Nagasena.Sax.Transmoverifier Exception:不应为文档结尾。

我使用的是c#实现,所以我在java实现中测试了这个问题——在那里它运行得很好。所以我试着改变一些选择,但无济于事。

当我用<Text><![CDATA[<]]></Text>替换<Text>&lt;</Text>,并从<Booo id="6001&lt;" />中删除&lt;-<Booo id="6001" />时,编码成功。但在属性中,不可能使用cdata,并且当它包含<>时或者CCD_ 7,则它以错误结束。

我将调试nagasena库,但如果有人有一些有用的建议,我将不胜感激。

thx

此问题是由于在Nagasena中使用了AElfred XML解析器造成的。最新的nagasena使用了Microsoft XML解析器,不应该再出现这个问题。

相关内容

最新更新