469,353 Members | 2,292 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,353 developers. It's quick & easy.

LF Example parsing XML from a string not a file

Say this may seem odd but I can't find an example of how to parse XML
that is passed in a string and not a file. All the examples assume you
want to parse a file not a a chunk of memory already read in.

Does any one have an example on the web?

Bob
Jul 20 '05 #1
4 12909
Maybe it works the same way in your mysterious programming language (whose
name you don't want us to know ;-) ) as in Java where
you construct InputSource from StringReader
see (look for StringReader)

http://www.ibiblio.org/xml/books/xml....html#d0e10201

with respect,
Toni Uusitalo

"Bob Sparks" <Bo*******@excite.com> wrote in message
news:9b**************************@posting.google.c om...
Say this may seem odd but I can't find an example of how to parse XML
that is passed in a string and not a file. All the examples assume you
want to parse a file not a a chunk of memory already read in.

Does any one have an example on the web?

Bob

Jul 20 '05 #2
Thanks

I did this

docBuilder.parse( new InputSource( new StringReader( userClassTree.toString() ) ) );

Now I need to figure out how to get the parser to decode
"S &amp; M toys" to
"S & M toys" when I getAttribute.

From reading the what Toni provided it looks like I need to setEncoding().

Bob
"Toni Uusitalo" <to**************@luukkudot.kom> wrote in message news:<As**************@reader1.news.jippii.net>...
Maybe it works the same way in your mysterious programming language (whose
name you don't want us to know ;-) ) as in Java where
you construct InputSource from StringReader
see (look for StringReader)

http://www.ibiblio.org/xml/books/xml....html#d0e10201

with respect,
Toni Uusitalo

"Bob Sparks" <Bo*******@excite.com> wrote in message
news:9b**************************@posting.google.c om...
Say this may seem odd but I can't find an example of how to parse XML
that is passed in a string and not a file. All the examples assume you
want to parse a file not a a chunk of memory already read in.

Does any one have an example on the web?

Bob

Jul 20 '05 #3
&whatever; constructs are entities (or < like things which are called
character references), they've got nothing to do with encoding. &amp; and 4
four other
predefined entities SHOULD have been decoded/expanded when your document
has been parsed i.e. you should get your "SAX & Markup toys" properly.
Check you parser's settings if there's something that preserves those
predefined entities.
(my Java xml parsing is a bit rusty at the moment, maybe somebody else could
help)

encoding: to put it short it's format in which you save/serialize your
document. When you load it you must have proper <? xml version="1.0"
encoding="whatever"?> set unless you're using (saved as) UTF-8 which is
default for parser if no encoding is specified.

http://www.ibiblio.org/xml/books/xmljava/ could give you answer on this too,
I recommend reading it, very useful book. reading it might be a bit on the S
&amp; M side for xml beginner in cos it's so detailed, but it's very good
book.

with respect,
Toni Uusitalo

"Bob Sparks" <Bo*******@excite.com> wrote in message
news:9b**************************@posting.google.c om...
Thanks

I did this

docBuilder.parse( new InputSource( new StringReader( userClassTree.toString() ) ) );
Now I need to figure out how to get the parser to decode
"S &amp; M toys" to
"S & M toys" when I getAttribute.

From reading the what Toni provided it looks like I need to setEncoding().

Bob
"Toni Uusitalo" <to**************@luukkudot.kom> wrote in message

news:<As**************@reader1.news.jippii.net>...
Maybe it works the same way in your mysterious programming language (whose name you don't want us to know ;-) ) as in Java where
you construct InputSource from StringReader
see (look for StringReader)

http://www.ibiblio.org/xml/books/xml....html#d0e10201

with respect,
Toni Uusitalo

"Bob Sparks" <Bo*******@excite.com> wrote in message
news:9b**************************@posting.google.c om...
Say this may seem odd but I can't find an example of how to parse XML
that is passed in a string and not a file. All the examples assume you
want to parse a file not a a chunk of memory already read in.

Does any one have an example on the web?

Bob

Jul 20 '05 #4
Something like this ...

Document doc = (new SAXBuilder()).build( new StringReader(xml));
Bo*******@excite.com (Bob Sparks) wrote in message news:<9b**************************@posting.google. com>...
Say this may seem odd but I can't find an example of how to parse XML
that is passed in a string and not a file. All the examples assume you
want to parse a file not a a chunk of memory already read in.

Does any one have an example on the web?

Bob

Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Michael Hogan | last post: by
5 posts views Thread by Aleksandar Matijaca | last post: by
4 posts views Thread by Gert Van den Eynde | last post: by
3 posts views Thread by VB Programmer | last post: by
1 post views Thread by Andre Ranieri | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.