D
David Svoboda
I have a server program that takes commands and acts on them. The
server program can also take these commands from an input file or
standard input (mainly for testing purposes). As such, I often have
files full of input commands to feed to the server.
Right now the commands that the server takes are well-defined, but not
in XML. Since the commands are not self-delimiting, I have to prepend
each command with a 'length' number indicating how many chars the
command takes.
I would like to change the server to accept XML commands, and provide
a DTD (or Schema or RelaxNG or ...) to ensure that the server only
receives valid commands.
My question is this: Can I take the length number out of my input
files & network commands? Since XML is self-delimiting (tags must
balance) this should be possible. However, every time I try to run a
Xerces (Java) parser on a file full of XML commands (with no length
info), it silently discards all but the first command.
I guess what I want to know is, can Xerces take an input stream full
of multiple XML trees and give me each XML tree in turn w/o discarding
any of them? (I can use either SAX or DOM or SAX2 to accomplish this.)
Several friends have suggested that I wrap the entire input file
around a <root> tag, which would make the series of commands into one
big giant happy XML file. I suppose that could work, but that has
several problems: (1) it requires a different DTD to handle multiple
commands than it does to handle one command. (2) as a server it
precludes me from using DOM since I need to act on each command before
the entire stream has been parsed.
Maybe this is the wrong forum to ask, but it's not clear what the
right forum would be. Is this feature covered in SAX? DOM? Is it
specific to Xerces?
~David Svoboda
server program can also take these commands from an input file or
standard input (mainly for testing purposes). As such, I often have
files full of input commands to feed to the server.
Right now the commands that the server takes are well-defined, but not
in XML. Since the commands are not self-delimiting, I have to prepend
each command with a 'length' number indicating how many chars the
command takes.
I would like to change the server to accept XML commands, and provide
a DTD (or Schema or RelaxNG or ...) to ensure that the server only
receives valid commands.
My question is this: Can I take the length number out of my input
files & network commands? Since XML is self-delimiting (tags must
balance) this should be possible. However, every time I try to run a
Xerces (Java) parser on a file full of XML commands (with no length
info), it silently discards all but the first command.
I guess what I want to know is, can Xerces take an input stream full
of multiple XML trees and give me each XML tree in turn w/o discarding
any of them? (I can use either SAX or DOM or SAX2 to accomplish this.)
Several friends have suggested that I wrap the entire input file
around a <root> tag, which would make the series of commands into one
big giant happy XML file. I suppose that could work, but that has
several problems: (1) it requires a different DTD to handle multiple
commands than it does to handle one command. (2) as a server it
precludes me from using DOM since I need to act on each command before
the entire stream has been parsed.
Maybe this is the wrong forum to ask, but it's not clear what the
right forum would be. Is this feature covered in SAX? DOM? Is it
specific to Xerces?
~David Svoboda