File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Parsing XML from a String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Parsing XML from a String" Watch "Parsing XML from a String" New topic

Parsing XML from a String

Dave Trower
Ranch Hand

Joined: Feb 12, 2003
Posts: 86
Is there a way to use the java XML parser to to parse an XML document that is contained in a String?
Currentlt my program creates a temp,xml file from the String variable and the uses the SAX parser to parse the file but I am sure there is a better way to do this.
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Sure thing. Check out if this FAQ for source code.

- m

Take a Minute, Donate an Hour, Change a Life
aravind yarram

Joined: Mar 28, 2003
Posts: 12
Create a StrignReader out of the XML in the String

Reader is=new StringReader(xmlString)

parser.setFeature( "",true);
parser.setFeature( "",VALIDATION);
parser.setFeature( "",true);
parser.setFeature( "",true);
parser.setFeature("", false);
parser.setFeature("", false);

parser.parse(new InputSource(is));

SCJP2<br />BEA Certified J2EE Developer
Dave Trower
Ranch Hand

Joined: Feb 12, 2003
Posts: 86
Thank you.
Your suggestion worked.
I agree. Here's the link:
subject: Parsing XML from a String
It's not a secret anymore!