首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nagasena/OpenExi:在属性中使用<编码xml

Nagasena/OpenExi:在属性中使用<编码xml
EN

Stack Overflow用户
提问于 2014-10-15 18:27:13
回答 1查看 517关注 0票数 0

我已经在C#中实现了长沙编码器:

代码语言:javascript
复制
 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();
        }
    }

我在编码包含<>或&lt;&gt;的简单有效的xml时遇到了问题:

代码语言:javascript
复制
<?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>

它只是以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库,但如果有人有一些有用的建议,我将不胜感激。

thx

EN

回答 1

Stack Overflow用户

发布于 2015-05-23 09:46:26

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26380247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档