LF Example parsing XML from a string not a file

Discussion in 'XML' started by Bob Sparks, Dec 15, 2003.

  1. Bob Sparks

    Bob Sparks Guest

    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
    Bob Sparks, Dec 15, 2003
    #1
    1. Advertising

  2. 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/xmljava/chapters/ch07s02.html#d0e10201

    with respect,
    Toni Uusitalo

    "Bob Sparks" <> wrote in message
    news:...
    > 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
    Toni Uusitalo, Dec 15, 2003
    #2
    1. Advertising

  3. Bob Sparks

    Bob Sparks Guest

    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" <> wrote in message news:<AsrDb.151$>...
    > 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/xmljava/chapters/ch07s02.html#d0e10201
    >
    > with respect,
    > Toni Uusitalo
    >
    > "Bob Sparks" <> wrote in message
    > news:...
    > > 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
    Bob Sparks, Dec 16, 2003
    #3
  4. &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" <> wrote in message
    news:...
    > 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" <> wrote in message

    news:<AsrDb.151$>...
    > > 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/xmljava/chapters/ch07s02.html#d0e10201
    > >
    > > with respect,
    > > Toni Uusitalo
    > >
    > > "Bob Sparks" <> wrote in message
    > > news:...
    > > > 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
    Toni Uusitalo, Dec 16, 2003
    #4
  5. Bob Sparks

    GIMME Guest

    Something like this ...

    Document doc = (new SAXBuilder()).build( new StringReader(xml));


    (Bob Sparks) wrote in message news:<>...
    > 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
    GIMME, Dec 16, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VB Programmer

    Example needed: simple XML file and parsing

    VB Programmer, Jan 6, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    772
    Craig Deelsnyder
    Jan 6, 2004
  2. Per Magnus L?vold
    Replies:
    0
    Views:
    1,359
    Per Magnus L?vold
    Nov 15, 2004
  3. Kee Nethery
    Replies:
    12
    Views:
    2,033
    Stefan Behnel
    Jun 27, 2009
  4. John Levine
    Replies:
    0
    Views:
    710
    John Levine
    Feb 2, 2012
  5. Erik Wasser
    Replies:
    5
    Views:
    416
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page