You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by rong <ry...@cs.umbc.edu> on 2000/04/13 20:49:03 UTC
parse XML String in java code
Hi,
If i want to parse a String(in a piece of java code), which is in form of
XML document, what should i do? The String can be in form of:
String s1 = " <POEM> <AUTHOR> Ogden Nash </AUTHOR> <TITLE> Fleas </TITLE>
<LINE> Adam had'em. </LINE></POEM> ";
In SAXParser, the function:
Parser parser = ParserFactory.makeParser("com.ibm.xml.parsers.SAXParser");
parser.setDocumentHandler(titleFinder);
parser.parse(new InputSource(args[0]));
can take an instance of File class(args[0]="*.xml") and parse it according
to an instance usr-defined class(titleFinder). This method basically parse
a xml file, not a String in the code.
Is there a way to parse a XML String in cocoon or another way?
Thanks,
Rong
Re: parse XML String in java code
Posted by Giacomo Pati <Gi...@pwr.ch>.
rong wrote:
>
> Hi,
>
> If i want to parse a String(in a piece of java code), which is in form of
> XML document, what should i do? The String can be in form of:
>
> String s1 = " <POEM> <AUTHOR> Ogden Nash </AUTHOR> <TITLE> Fleas </TITLE>
> <LINE> Adam had'em. </LINE></POEM> ";
>
> In SAXParser, the function:
>
> Parser parser = ParserFactory.makeParser("com.ibm.xml.parsers.SAXParser");
> parser.setDocumentHandler(titleFinder);
> parser.parse(new InputSource(args[0]));
Use: parser.parse (new InputSource (new StringReader (s1));
Giacomo
>
> can take an instance of File class(args[0]="*.xml") and parse it according
> to an instance usr-defined class(titleFinder). This method basically parse
> a xml file, not a String in the code.
>
> Is there a way to parse a XML String in cocoon or another way?
>
> Thanks,
>
> Rong
--
PWR Organisation & Entwicklung Tel: +41 (0)1 856 2202
Giacomo Pati Fax: +41 (0)1 856 2201
Hintereichenstrasse 7 Mailto:Giacomo.Pati@pwr.ch
CH-8166 Niederweningen Web: http://www.pwr.ch