Results 1 to 3 of 3

Thread: Xml + Sax

  1. #1
    Jack is offline Senior Member
    Join Date
    Jun 2007
    Posts
    130
    Rep Power
    0

    Default 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

  2. #2
    Ed
    Ed is offline Senior Member
    Join Date
    Jun 2007
    Posts
    110
    Rep Power
    0

    Default

    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.

  3. #3
    bbq
    bbq is offline Senior Member
    Join Date
    Jun 2007
    Posts
    132
    Rep Power
    0

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •