Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: Xerces-J question

Reply
Thread Tools

Re: Xerces-J question

 
 
Arne Vajh°j
Guest
Posts: n/a
 
      11-01-2008
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
 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      11-02-2008
Konstantinos Agouros wrote:
> In <1225619923.153697@rumba> Konstantinos Agouros <(E-Mail Removed)> writes:
>> In <490c875c$0$90263$(E-Mail Removed)> =?ISO-8859-1?Q?Arne_Vajh=F8j?= <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Stanimir Stamenkov
Guest
Posts: n/a
 
      11-02-2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question row filter (more of sql query question) =?Utf-8?B?YW5kcmV3MDA3?= ASP .Net 2 10-06-2005 01:07 PM
Quick Question - Newby Question =?Utf-8?B?UnlhbiBTbWl0aA==?= ASP .Net 4 02-16-2005 11:59 AM
Question on Transcender Question :-) eddiec MCSE 6 05-20-2004 06:59 AM
Question re: features of the 831 router (also a 924 question) Wayne Cisco 0 03-02-2004 07:57 PM
Syntax Question - Novice Question sean ASP .Net 1 10-20-2003 12:18 PM



Advertisments