Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

How to read a cdata using sax parser

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to XML & i want to read a query from xml.
which will be in cdata tag.
please help me by providing source code for reading cdata usin sax parser.
thanx in advance
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use the following snippet- the characters() method would catch any CDATA sections within XML:


[ December 07, 2005: Message edited by: Bajji Pat ]
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for providing the code.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have still a lot to learn in programming and I'm sorry for this stupid question.
But i was wondering how to use this code ?

Can you modify it to read txt files or html?

Will anyone be kind enough to reply to this question?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
XML *is* text. But text is not normally XML, and neither is HTML. So, no, you can't use a SAX parser for reading text files in general or HTML.

But the question is: why would you want to? What are you trying to accomplish?
 
Jeremie Juste
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many thanks for the help

In fact i'm doing some web scraping and want to get some data found in between the CData.

I have found a nice code doing part of this job.
http://www.java-tips.org/java-se-tips/org.xml.sax/accessing-character-data-cdata-of-xml-element.html

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HTML is not generally XML. I suspect that this code will not work for 99% of all web pages in existence (doesn't mean it won't work for any particular page you're interested in, of course, especially if that page happens to be XHTML).
reply
    Bookmark Topic Watch Topic
  • New Topic