File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Parsing a String using DOM API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Parsing a String using DOM API" Watch "Parsing a String using DOM API" New topic
Author

Parsing a String using DOM API

Lakshmi Ramachandran
Greenhorn

Joined: Jun 26, 2001
Posts: 26
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

Joined: Mar 17, 2000
Posts: 5782
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.


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Lakshmi Ramachandran
Greenhorn

Joined: Jun 26, 2001
Posts: 26
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

Joined: Mar 22, 2000
Posts: 12809
    
    5
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

Joined: Jul 17, 2001
Posts: 3
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]

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parsing a String using DOM API