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 Jon Arnar Gudmundsson <jo...@vhr.is> on 2000/04/30 15:08:17 UTC

Parsing xml in memory

Hi all,

I am unable to browse the archives at webweaving.org so I post this question
on the mailing list... I am trying to parse an xml String that my program
receives. All the samples that came with the parser use an xml file. I have
seen how to do this with the xerces C++ parser, but I can't figure out how
do pass a String to the parser to parse...

Any suggestions will be welcome.

thanks,

Jon Gudmundsson

RE: Parsing xml in memory

Posted by Baq Haidri <bh...@inktomi.com>.
no problem, any time!

At 11:34 PM 4/30/00 +0000, you wrote:
>howdy,
>
>thanks for the tip, this is exactly what I needed. Maybe I'll go home 
>early tonight to celebrate this small victory :)
>
>- jonarnar
>>-----Original Message-----
>>From: Baq Haidri [mailto:bhaidri@inktomi.com]
>>Sent: Sunday, April 30, 2000 9:51 PM
>>To: xerces-j-dev@xml.apache.org
>>Subject: RE: Parsing xml in memory
>>
>>Hi,
>>The StringReader mentioned in the example is the java.io.StringReader not 
>>the org.apache.xerces one.  In fact you can pretty much use any of Java's 
>>reader or stream classes which means you can parse a file from memory, 
>>data from a database, or from an incoming stream, say over the web:
>>
>>For example i have created my own reader class XMLBufferedReader which 
>>extends java.io.BufferedReader and have supplied a file name to it and 
>>then passed that reader on to the InputSource object:
>>
>>       XMLBufferedReader reader = new XMLBufferedReader(new 
>> FileReader("D:/Test.xml"));
>>       InputSource source = new InputSource(reader);
>>
>>You can also do this with a stream
>>
>>         InputStream inStream = new InputStream(some input stream);
>>         InputSource source = new InputSource(inStream);
>>
>>Therefore you don't even have to have a file.
>>
>>--baq
>>
>>
>>
>>At 09:39 PM 4/30/00 +0000, you wrote:
>>>hi,
>>>the org.apache.xerces.reader.StringReader is not a public class so I can 
>>>not use that one. Even when I tried to modify the source and change 
>>>StringReader to a public class, I still got errors as the constructor 
>>>for StringReader is:
>>>
>>>private StringReader(XMLEntityHandler entityHandler, XMLErrorReporter 
>>>errorReporter,
>>>                          boolean sendCharDataAsCharArray, int 
>>> lineNumber, int columnNumber,
>>>                          int stringHandle, StringPool stringPool, 
>>> boolean addEnclosingSpaces)
>>>
>>>-- so it is not possible to pass a String to the constructor. Is there 
>>>any other way to parse a file from memory and not from a file?
>>>
>>>thanks,
>>>
>>>jonarnar
>>>-----Original Message-----
>>>From: Baq Haidri [mailto:bhaidri@inktomi.com]
>>>
>>>I found this in a book called 'Professional XML' by Wrox publishing:
>>>
>>>public void parseString(String s) throws SAXException, IOException
>>>{
>>>         StringReader reader = new SringReader(s);
>>>         InputSource source = new InputSource(reader);
>>>         parser.parse(source);
>>>}
>>>
>>>
>>>
>>>
>>>
>>>I hope this is what you were looking for...
>>>
>>>Good luck,
>>>Baq Haidri
>>>
>>>
>>>
>>>
>>>
>>>At 01:08 PM 4/30/00 +0000, you wrote:
>>>>Hi all,
>>>>
>>>>I am unable to browse the archives at webweaving.org so I post this 
>>>>question on the mailing list... I am trying to parse an xml String that 
>>>>my program receives. All the samples that came with the parser use an 
>>>>xml file. I have seen how to do this with the xerces C++ parser, but I 
>>>>can't figure out how do pass a String to the parser to parse...
>>>>
>>>>Any suggestions will be welcome.
>>>>
>>>>thanks,
>>>>
>>>>Jon Gudmundsson
>>>
>

RE: Parsing xml in memory

Posted by Jon Arnar Gudmundsson <jo...@vhr.is>.
howdy,

thanks for the tip, this is exactly what I needed. Maybe I'll go home early
tonight to celebrate this small victory :)

- jonarnar
  -----Original Message-----
  From: Baq Haidri [mailto:bhaidri@inktomi.com]
  Sent: Sunday, April 30, 2000 9:51 PM
  To: xerces-j-dev@xml.apache.org
  Subject: RE: Parsing xml in memory


  Hi,
  The StringReader mentioned in the example is the java.io.StringReader not
the org.apache.xerces one.  In fact you can pretty much use any of Java's
reader or stream classes which means you can parse a file from memory, data
from a database, or from an incoming stream, say over the web:

  For example i have created my own reader class XMLBufferedReader which
extends java.io.BufferedReader and have supplied a file name to it and then
passed that reader on to the InputSource object:

        XMLBufferedReader reader = new XMLBufferedReader(new
FileReader("D:/Test.xml"));
        InputSource source = new InputSource(reader);

  You can also do this with a stream

          InputStream inStream = new InputStream(some input stream);
          InputSource source = new InputSource(inStream);

  Therefore you don't even have to have a file.

  --baq


  At 09:39 PM 4/30/00 +0000, you wrote:

    hi,
    the org.apache.xerces.reader.StringReader is not a public class so I can
not use that one. Even when I tried to modify the source and change
StringReader to a public class, I still got errors as the constructor for
StringReader is:

    private StringReader(XMLEntityHandler entityHandler, XMLErrorReporter
errorReporter,
                             boolean sendCharDataAsCharArray, int
lineNumber, int columnNumber,
                             int stringHandle, StringPool stringPool,
boolean addEnclosingSpaces)

    -- so it is not possible to pass a String to the constructor. Is there
any other way to parse a file from memory and not from a file?

    thanks,

    jonarnar
        -----Original Message-----
        From: Baq Haidri [mailto:bhaidri@inktomi.com]


        I found this in a book called 'Professional XML' by Wrox publishing:


        public void parseString(String s) throws SAXException, IOException


                StringReader reader = new SringReader(s);
                InputSource source = new InputSource(reader);
                parser.parse(source);
        }




        I hope this is what you were looking for...


        Good luck,
        Baq Haidri




        At 01:08 PM 4/30/00 +0000, you wrote:
          Hi all,

          I am unable to browse the archives at webweaving.org so I post
this question on the mailing list... I am trying to parse an xml String that
my program receives. All the samples that came with the parser use an xml
file. I have seen how to do this with the xerces C++ parser, but I can't
figure out how do pass a String to the parser to parse...

          Any suggestions will be welcome.

          thanks,

          Jon Gudmundsson



RE: Parsing xml in memory

Posted by Baq Haidri <bh...@inktomi.com>.
Hi,
The StringReader mentioned in the example is the java.io.StringReader not 
the org.apache.xerces one.  In fact you can pretty much use any of Java's 
reader or stream classes which means you can parse a file from memory, data 
from a database, or from an incoming stream, say over the web:

For example i have created my own reader class XMLBufferedReader which 
extends java.io.BufferedReader and have supplied a file name to it and then 
passed that reader on to the InputSource object:

       XMLBufferedReader reader = new XMLBufferedReader(new 
FileReader("D:/Test.xml"));
       InputSource source = new InputSource(reader);

You can also do this with a stream

         InputStream inStream = new InputStream(some input stream);
         InputSource source = new InputSource(inStream);

Therefore you don't even have to have a file.

--baq


At 09:39 PM 4/30/00 +0000, you wrote:
>hi,
>the org.apache.xerces.reader.StringReader is not a public class so I can 
>not use that one. Even when I tried to modify the source and change 
>StringReader to a public class, I still got errors as the constructor for 
>StringReader is:
>
>private StringReader(XMLEntityHandler entityHandler, XMLErrorReporter 
>errorReporter,
>                          boolean sendCharDataAsCharArray, int lineNumber, 
> int columnNumber,
>                          int stringHandle, StringPool stringPool, boolean 
> addEnclosingSpaces)
>
>-- so it is not possible to pass a String to the constructor. Is there any 
>other way to parse a file from memory and not from a file?
>
>thanks,
>
>jonarnar
>>-----Original Message-----
>>From: Baq Haidri [mailto:bhaidri@inktomi.com]
>>
>>I found this in a book called 'Professional XML' by Wrox publishing:
>>
>>public void parseString(String s) throws SAXException, IOException
>>{
>>         StringReader reader = new SringReader(s);
>>         InputSource source = new InputSource(reader);
>>         parser.parse(source);
>>}
>>
>>
>>
>>I hope this is what you were looking for...
>>
>>Good luck,
>>Baq Haidri
>>
>>
>>
>>At 01:08 PM 4/30/00 +0000, you wrote:
>>>Hi all,
>>>
>>>I am unable to browse the archives at webweaving.org so I post this 
>>>question on the mailing list... I am trying to parse an xml String that 
>>>my program receives. All the samples that came with the parser use an 
>>>xml file. I have seen how to do this with the xerces C++ parser, but I 
>>>can't figure out how do pass a String to the parser to parse...
>>>
>>>Any suggestions will be welcome.
>>>
>>>thanks,
>>>
>>>Jon Gudmundsson
>

RE: Parsing xml in memory

Posted by Jon Arnar Gudmundsson <jo...@vhr.is>.
hi,
the org.apache.xerces.reader.StringReader is not a public class so I can not
use that one. Even when I tried to modify the source and change StringReader
to a public class, I still got errors as the constructor for StringReader
is:

private StringReader(XMLEntityHandler entityHandler, XMLErrorReporter
errorReporter,
                         boolean sendCharDataAsCharArray, int lineNumber,
int columnNumber,
                         int stringHandle, StringPool stringPool, boolean
addEnclosingSpaces)

-- so it is not possible to pass a String to the constructor. Is there any
other way to parse a file from memory and not from a file?

thanks,

jonarnar
  -----Original Message-----
  From: Baq Haidri [mailto:bhaidri@inktomi.com]


  I found this in a book called 'Professional XML' by Wrox publishing:

  public void parseString(String s) throws SAXException, IOException
  {
          StringReader reader = new SringReader(s);
          InputSource source = new InputSource(reader);
          parser.parse(source);
  }


  I hope this is what you were looking for...

  Good luck,
  Baq Haidri


  At 01:08 PM 4/30/00 +0000, you wrote:

    Hi all,

    I am unable to browse the archives at webweaving.org so I post this
question on the mailing list... I am trying to parse an xml String that my
program receives. All the samples that came with the parser use an xml file.
I have seen how to do this with the xerces C++ parser, but I can't figure
out how do pass a String to the parser to parse...

    Any suggestions will be welcome.

    thanks,

    Jon Gudmundsson



Re: Parsing xml in memory

Posted by Baq Haidri <bh...@inktomi.com>.
I found this in a book called 'Professional XML' by Wrox publishing:

public void parseString(String s) throws SAXException, IOException
{
         StringReader reader = new SringReader(s);
         InputSource source = new InputSource(reader);
         parser.parse(source);
}


I hope this is what you were looking for...

Good luck,
Baq Haidri


At 01:08 PM 4/30/00 +0000, you wrote:
>Hi all,
>
>I am unable to browse the archives at webweaving.org so I post this 
>question on the mailing list... I am trying to parse an xml String that my 
>program receives. All the samples that came with the parser use an xml 
>file. I have seen how to do this with the xerces C++ parser, but I can't 
>figure out how do pass a String to the parser to parse...
>
>Any suggestions will be welcome.
>
>thanks,
>
>Jon Gudmundsson