Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-04-2007, 10:33 AM
Senior Member
 
Join Date: Jun 2007
Posts: 130
Jack is on a distinguished road
Xml + Sax
Hello!!

I'm trying to obtein an XML response from a server through a socket, and parsing it with SAX. On the server side the communication (i.e. the socket) should keep alive beyond each response.

My problem is that the parser keeps waiting for more data because the socket doesn't close after the response.

I've made something like a tricky solution by doing a response preview by myself and detecting the route tag. I create a separated StringReader where I append the text already read and once I recognize the closing route tag I stop reading from the socket and create a new InputSource for the parser.

I don`t like this solution, because I'm quite parsing the message twice and I must also keep a buffer for a possible piece of future message already read so as to include it in a future response.

What is the right solution here ?

Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-04-2007, 10:34 AM
Ed Ed is offline
Senior Member
 
Join Date: Jun 2007
Posts: 110
Ed is on a distinguished road
Your parser could read the first tag that it gets. Then, it would keep reading until it encounters the matching tag. After the matching tag is encountered, it would stop trying to get more data, being at the end of the XML document.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-04-2007, 10:35 AM
bbq bbq is offline
Senior Member
 
Join Date: Jun 2007
Posts: 134
bbq is on a distinguished road
1)add tag like <Size> which will represent a size of the message.
2)when you are reading response from stream you have to implement algorithm to make a read and analyze what you read checking whether you got full response or partial response and act accordingly.
3) you do not need to use parser for #2.
4) use your parser after you receive full message.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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

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



All times are GMT +3. The time now is 01:14 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org