dcsimg
Splitting =2 XML objects on an input stream
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   David_Svoboda
Posted On:   Thursday, November 13, 2003 08:42 AM

I have to write a program that takes a list of commands and sends each command to a server. Each command is an well-formed XML document, and the commands are fed to me via an input stream. (That is, they may come from standard input, or a file, or a socket.) The difficulty is that if I feed the entire input stream to the SAX or DOM parser, the parser parses the first command on the stream, and discards the rest. If I try calling it again on your input stream, I get an end-of-file error. Right now, my current alternatives are as follows: Do my own XML parsing...at least enough parsing to know when I have finished reading a single command. (T   More>>

I have to write a program that takes a list of commands and sends each
command to a server. Each command is an well-formed XML document, and
the commands are fed to me via an input stream. (That is, they may
come from standard input, or a file, or a socket.)



The difficulty is that if I feed the entire input stream to the SAX or
DOM parser, the parser parses the first command on the stream, and
discards the rest. If I try calling it again on your input stream, I
get an end-of-file error.



Right now, my current alternatives are as follows:

  • Do my own XML parsing...at least enough parsing to know when I have
    finished reading a single command. (This might actually be reasonable,
    since these commands are much simpler than XML allows for...for
    instance, I know they are straight ASCII.)

  • Wrap the input stream commands inside some sort of
    tag...thus the list of commands becomes a single XML 'document'. You
    can then parse it with SAX and build each command. Or parse into a DOM
    structure, and extract each command from the DOM tree. This has the
    disadvantage that you must have the entire list of commands available
    before the first one gets processed. Which is reasonable for parsing a
    file of commands, but not reasonable if the commands were being
    entered in interactively, or coming in over a socket.

  • Wrap the commands inside some sort of tag, and use the SAX
    parser, instructing it to process each command as it finishes reading
    them. This sidesteps the disadvantage described above. But it requires
    that you let the SAX parser control your code, and your
    command-processing routine is called upon the whim of the SAX parser.


Is there any way to parse an XML command off the input stream without
closing the input stream or losing the subsequent commands?    <<Less

Re: Splitting =2 XML objects on an input stream

Posted By:   Anonymous  
Posted On:   Friday, November 14, 2003 02:49 AM

Reinitializing the parser after finishing one command?
About | Sitemap | Contact