aspose file tools*
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
Author

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
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
aravind yarram
Greenhorn

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

Reader is=new StringReader(xmlString)

parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",schemaFileLocation);
parser.setFeature( "http://apache.org/xml/features/validation/schema",true);
parser.setFeature("http://apache.org/xml/features/validation/schema",false);
parser.setContentHandler(yourContentHandler);
parser.setErrorHandler(yourErrorHandler);
parser.setFeature( "http://xml.org/sax/features/validation",VALIDATION);
parser.setFeature( "http://xml.org/sax/features/namespaces",true);
parser.setFeature("http://apache.org/xml/features/validation/schema",true);
parser.setFeature( "http://apache.org/xml/features/validation/schema-full-checking",true);
parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false);
parser.setFeature("http://apache.org/xml/features/validation/dynamic", 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: http://aspose.com/file-tools
 
subject: Parsing XML from a String