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?To: NULL Date: 4/30/2009 9:56:00 AM RC wrote:
> 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?
Via the 'characters()' method.
> What shall I do in these two methods?
Mark the beginning and end of each element so that your parser knows
where it is in the parse process.
> @Override
> public void startElement(String uri, String localName, String qName,
> Attributes attributes)
> throws SAXException
> {
> =A0 =A0 =A0 =A0 if (qName.equals("script"))
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 // How to retrieve my script contents?
Not here. What do the Javadocs tell you about the purpose of this
method and the event it handles?
> =A0 =A0 =A0 =A0 }}
>
> @Override
> public void endElement(String uri, String localName, String qName)
> throws SAXException
> {
> =A0 =A0 =A0 =A0 if (qName.equals("script"))
> =A0 =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 // How to retrieve my script contents?
Not here. What do the Javadocs tell you about the purpose of this
method and the event it handles?
> =A0 =A0 =A0 =A0 }
>
> }
>
> Below two methods have no print out at all
Did you read the Javadocs?
> @Override
> public void endCDATA()
> {
> =A0 =A0 =A0 =A0 System.out.println("End of CDATA");
> }
>
> @Override
> public void startCDATA()
> {
> =A0 =A0 =A0 =A0 System.out.println("Start of CDATA");
> }
The Javadocs will tell you:
> The contents of the CDATA section will be reported through the regular
> characters event; this event is intended only to report the boundary.
While not always enough, the API Javadocs are always a good place to
start, and often will completely answer your questions.
--
Lew
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
