Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parsing a String using DOM API

 
Lakshmi Ramachandran
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,
I am writing an application in Java using DOM API. I have done the parsing of an XML document by passing its file name as a String parameter to the parse method of DOMParser class. This woks fine.
Now, I would like to pass the XML documentas a String and parse.
Please help me doing this task.
Regards,
Lakshmi
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In order to parse an XML string, you will need to use an InputSource instance. Try this -

Hope that helps!
------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.
 
Lakshmi Ramachandran
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ajith,
I am currently using ByteArrayInputStream object as a parameter to InputSource constructor. I will try with StringBufferInputStream now. But otherwise, instead of using InputSource, is there any way of sending XML String for parsing !
Please let me Know.
Regards,
Lakshmi
[This message has been edited by Lakshmi Ramachandran (edited July 17, 2001).]
[This message has been edited by Lakshmi Ramachandran (edited July 17, 2001).]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the API for your parser. In JAXP 1.1 I find parse() methods with input of File, InputSource, InputStream, and URI.
Bill

------------------
author of:
 
Mahesh Siddanati
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
i was trying to do what u had suggested for parsing an xml string,but the compiler says
C:\Mahesh\BlueEdge>javac -deprecation testxml.java
testxml.java:73: warning: java.io.StringBufferInputStream in java.io has been deprecated
InputStream is = new StringBufferInputStream(xmldata) ;
^
1 warning
any ideas what i should be using instead
Thanks,
Mahesh

Originally posted by Ajith Kallambella:
[B]In order to parse an XML string, you will need to use an InputSource instance. Try this -

Hope that helps!
[/B]

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic