简体   繁体   中英

Sax parser : get tagcontent below child tag

Is there a way to get CDATA tag content from the following xml tag (category):

 <category>
    <h1>Some data</h1>
    <![CDATA[<br> some data ...]]>
    <h1>Some data</h1>
    <![CDATA[<br> more data ...]]> 
</category>

Could somehow characters method get only content inside category tag but outside h1 tags?

Thanks

  1. Override startCDATA() and endCDATA() methods in DefaultHandler2 implementation.

     DefaultHandler2 handler2 = new DefaultHandler2() { /* ... */ } 
  2. Configure XMLReader

     SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); XMLReader xmlReader = saxParser.getXMLReader(); xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler2); 
  3. Start parsing

     saxParser.parse( /* input source */, handler2); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM