使用SAX进行XML解析

编程入门 行业动态 更新时间:2024-10-22 17:30:49
本文介绍了使用SAX进行XML解析|如何处理特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们有一个JAVA应用程序,可以从SAP中提取数据,进行解析并将其呈现给用户. 使用JCO连接器提取数据.

We have a JAVA application that pulls the data from SAP, parses it and renders to the users. The data is pulled using JCO connector.

最近我们被抛出了一个异常:

Recently we were thrown an exception:

org.xml.sax.SAXParseException: Character reference "&#00" is an invalid XML character.

因此,我们计划编写一个新的间接级别,其中在解析XML之前,将替换所有特殊/非法字符.

So, we are planning to write a new level of indirection where ALL special/illegal characters are replaced BEFORE parsing the XML.

我的问题是:

  • 是否有任何现有的(开放源代码)实用程序可以代替XML中的非法字符?
  • 或者如果我必须编写这样的实用程序,我应该如何处理它们?
  • 为什么会引发上述异常?
  • 谢谢.

    推荐答案

    听起来像是他们转义中的错误.根据上下文的不同,您最好只编写自己的使用真实XML库的XMLWriter类版本,而不是像SAP开发人员那样尝试编写自己的XML实用程序.

    It sounds like a bug in their escaping. Depending on context you might be best off just writing your own version of their XMLWriter class that uses a real XML library rather than trying to write your own XML utilities like the SAP developers did.

    或者,查看字符代码&#00,也许可以用空字符串替换掉所有字符:

    Alternatively, looking at the character code, &#00, you might be able to get away with a replace all on it with the empty string:

    String goodXml = badXml.replaceAll("�", "");

    更多推荐

    使用SAX进行XML解析

    本文发布于:2023-10-29 10:00:56,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1539404.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:SAX   XML

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!