Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - How to retrieve XML CDATA text contents by org.xml.sax.ext.DefaultHandler2? >Thread Next - Re: How to retrieve XML CDATA text contents by org.xml.sax.ext.DefaultHandler2? Re: How to retrieve XML CDATA text contents by org.xml.sax.ext.DefaultHandler2?To: NULL Date: 5/4/2009 4:01:00 PM Thu, 30 Apr 2009 12:02:36 -0400, /RC/:
> For example I have a XML tag
>
> <script>
> <![CDATA[
> My script is here
> ]]>
> </script>
>
> I am using org.xml.sax.ext.DefaultHandler2 to parse my XML
> file. How do I retrieve my script contents?
You retrieve it as ordinary text content delivered through
'characters' events to your ContentHandler. Whether the text is
written as CDATA section (or not) in the source is purely a
syntactic detail which shouldn't bother you.
> Below two methods have no print out at all
> @Override
> public void endCDATA()
> {
> System.out.println("End of CDATA");
> }
>
> @Override
> public void startCDATA()
> {
> System.out.println("Start of CDATA");
> }
>
> Thank you very much in advance!
You need to set the "lexical-handler" [1] property of the parser
with the reference to your handler in addition to setting it as a
'contentHandler':
XMLReader parser;
DefaultHandler2 myHandler;
...
parser.setContentHandler(myHandler);
parser.setProperty("http://xml.org/sax/properties/"
+ "lexical-handler", myHandler);
[1] SAX2 Standard Handler and Property IDs
<http://www.saxproject.org/apidoc/org/xml/sax/package-summary.html>
--
Stanimir
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
