Java XML parsing: taking inner XML using SAX

若如初见. 提交于 2019-12-02 02:29:13

问题


I'm parsing an XML file with SAX and at some point I need the inner XML of an element. E.g., for the following XML

<a name="abc">
  <b>def</b>
<a>

I need to get the inner XML for the element a, which would be

<b>def<b>

What's the easiest way to do that?

Thanks.

Ivan


回答1:


For this type of situation I suggest using 2 content handlers. The first is responsible for finding the relevant part of the document, and the second for processing the content. My answer to a similar question (see link below) demonstrates how to implement this approach:

  • Using SAX to parse common XML elements


来源:https://stackoverflow.com/questions/5028613/java-xml-parsing-taking-inner-xml-using-sax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!