Re: Xerces-J question

Discussion in 'Java' started by Arne Vajhøj, Nov 1, 2008.

  1. Arne Vajhøj

    Arne Vajhøj Guest

    Konstantinos Agouros wrote:
    > I am using xerces-j on a GUI that connects to a perl server. It retrieves
    > it's data in an XML-stream. I am currently changing from SAX processing to
    > DOM-Processing. My idea is that the gui keeps the same socket open and if
    > data is available calls parse on the socket (or the InputSource encapsulating
    > it) to parse the XML-document sent by the server.
    >
    > Using SAX and eventhandlers this is working. But parse() from a DOMParser
    > hangs I guess because it waits for an EOF on the socket. Is there another
    > way than reading the XML in a string and then parsing that?


    DOM pareses the entire doc until EOF before it is ready. That is
    the design.

    Either you stay with SAX or you change the protcol so that
    instead of reading a single streamed XML document you read
    multiple smaller XML documents. You will need to read
    the doc to memory and parse from there, but it is doable.

    Arne
    Arne Vajhøj, Nov 1, 2008
    #1
    1. Advertising

  2. Arne Vajhøj

    Arne Vajhøj Guest

    Konstantinos Agouros wrote:
    > In <1225619923.153697@rumba> Konstantinos Agouros <> writes:
    >> In <490c875c$0$90263$> =?ISO-8859-1?Q?Arne_Vajh=F8j?= <> writes:
    >>> Konstantinos Agouros wrote:
    >>>> I am using xerces-j on a GUI that connects to a perl server. It retrieves
    >>>> it's data in an XML-stream. I am currently changing from SAX processing to
    >>>> DOM-Processing. My idea is that the gui keeps the same socket open and if
    >>>> data is available calls parse on the socket (or the InputSource encapsulating
    >>>> it) to parse the XML-document sent by the server.
    >>>>
    >>>> Using SAX and eventhandlers this is working. But parse() from a DOMParser
    >>>> hangs I guess because it waits for an EOF on the socket. Is there another
    >>>> way than reading the XML in a string and then parsing that?

    >
    >>> DOM pareses the entire doc until EOF before it is ready. That is
    >>> the design.

    >
    >>> Either you stay with SAX or you change the protcol so that
    >>> instead of reading a single streamed XML document you read
    >>> multiple smaller XML documents. You will need to read
    >>> the doc to memory and parse from there, but it is doable.

    >> OK EOF by design answers my question so I will collect it in a string and parse that. just wanted to know if that's the 'right way'.

    > OK I collected the XML now I want to parse it. DOMParser.parse(string) doesn't
    > work on an xml-string. So how do I continue here?


    Document doc = db.parse(new InputSource(new StringReader(s)));

    But I would have went for:

    Document doc = db.parse(new ByteArrayInputStream(b));

    Arne
    Arne Vajhøj, Nov 2, 2008
    #2
    1. Advertising

  3. Sun, 2 Nov 2008 19:56:48 +0000 (UTC), /Konstantinos Agouros/:

    > OK I collected the XML now I want to parse it. DOMParser.parse(string) doesn't
    > work on an xml-string. So how do I continue here?


    Why you should interface with the Xerces specific classes? Isn't
    the JAXP DocumentBuilder just enough for you?

    At any rate, both classes provide parse(org.xml.sax.InputSource)
    method where you could invoke it as:

    String xmlText;
    ....
    parser.parse(new InputSource(new java.io.StringReader(xmlText)));

    If you have got the source as bytes:

    byte[] xmlBuf;
    ....
    parser.parse(new InputSource(new java.io.ByteArrayInputStream(xmlBuf));

    But that's all pretty basic stuff you should be aware of, I think.

    --
    Stanimir
    Stanimir Stamenkov, Nov 2, 2008
    #3
    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. Bekkali Hicham

    Question about Xerces ????

    Bekkali Hicham, Jun 27, 2003, in forum: XML
    Replies:
    2
    Views:
    926
    Jean-Marc Vanel
    Jul 5, 2003
  2. Bassa
    Replies:
    0
    Views:
    973
    Bassa
    Sep 19, 2003
  3. Naren
    Replies:
    1
    Views:
    612
    Martin Honnen
    Nov 21, 2003
  4. David
    Replies:
    4
    Views:
    3,804
    Toni Uusitalo
    Dec 17, 2003
  5. cvissy
    Replies:
    0
    Views:
    601
    cvissy
    Nov 16, 2004
Loading...

Share This Page