English 中文(简体)
阅读XML和SAX, 绕过电线的 no子
原标题:Reading an XML with SAX, skipping the nodes that passes org.xml.sax.SAXParseException

我正在使用SAX(javax.xml.parsers.SAXParser;)阅读XML。 在《少年儿童法》中,某些特殊性,如(和;及,>)等,存在于儿童 no价值中。 因此,从那时起,SAX公司成功地读了XML,但在此刻,它投下了<条码>。

例如,在下文样本XML中,SAX读到了成功的价值。 但是,从Name 论点的价值<>>><<>>>/strong> 开始,它就投下了这一条。

<Parent>
   <child1>
      LS-23541723
   </child1>
   <child2 id="2" Name="T-Shirt And Denim - T<D" Rate="500.00">
   </child2>
   <child3>
      <![CDATA[This is the child 2]]>
   </child3>
   <child4>
      <![CDATA[This is the child 4]]>
   </child4>
</Parent>

I can t determine the nodes that contains these special characters before hand.(It is dyanamic.) So, What I wanna do is, reading an XML with SAX, ignoring the nodes that contains these like special characters.. Simply, I think I can do this if it is possible to read the XML with SAX, skipping the nodes that pass the org.xml.sax.SAXParseException.

这是可能的,如果是的话?

说明:我不能简单地以实体保留取代这些保留,例如<代码>和复制;。 自此以后,一些时候,XML节点与<代码>&lt;,&gt;以及(作为&lt;child1&gt;。 因此,在开始用空间研究局读一读之前,我以特性参考资料取代所有实体参考资料。

最佳回答

I don t think that SAX can handle this. The XML has to be well-formed. Thus you have to make a bunch of replacements before the text is submitted to SAX. Look for any , " or < that are not in the right places. " between ", between and < that is not part of a start tag or end tag. That should be feasible. That s the second pass after your first pass that replaces &lt; and &gt; by their equivalent counterparts. Ideally you should also watch for comments, CDATA section, etc... to be sure they are well-formed.

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...