Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: How to retrieve XML CDATA text contents by org.xml.sax.ext.DefaultHandler2?

From: Lew <lew@---------.--->
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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent