You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Brian Dobby <bd...@nobilis.com> on 2001/01/10 16:14:52 UTC
Newbie: Parse XML from a String?
Hi, folks.
Sorry if this is a stupid question, but I'm on another 'in at the
deep end' project...
DOMParser.parse takes a String argument which it treats as a URI. Is
their any way that I can parse XML from a String without writing it out to a
file first?
TIA
Brian
Re: Newbie: Parse XML from a String?
Posted by Andy Clark <an...@apache.org>.
Brian Dobby wrote:
> DOMParser.parse takes a String argument which it treats as a
> URI. Is their any way that I can parse XML from a String without
> writing it out to a file first?
Use the following:
Reader reader = new StringReader("<root/>");
InputSource source = new InputSource(reader);
parser.parse(source);
This really needs to be in the FAQ.
--
Andy Clark * IBM, TRL - Japan * andyc@apache.org
Re: Newbie: Parse XML from a String?
Posted by Ian Roberts <ir...@decisionsoft.com>.
On Wed, 10 Jan 2001, Brian Dobby wrote:
> Hi, folks.
> Sorry if this is a stupid question, but I'm on another 'in at the
> deep end' project...
>
> DOMParser.parse takes a String argument which it treats as a URI. Is
> their any way that I can parse XML from a String without writing it out to a
> file first?
DOMParser can parse from an InputSource, so if your XML is in the
xmlString, you can do:
InputSource source = new InputSource(new StringReader(xmlString));
parser.parse(source);
Ian
--
Ian Roberts | irr@decisionsoft.com
DecisionSoft Ltd. | http://www.decisionsoft.com/