[Mono-list] parsing an incomplete xml

Scott Boston scott@spacehug.com
Mon, 19 Jul 2004 08:04:16 -0700


On Mon, 2004-07-19 at 01:46, Krisztian PIFKO wrote:
> On Sun, 2004-07-18 at 20:34 -0700, Scott Boston wrote:
> > How are you feeding the incomplete xml into the XmlTextReader? 
> 
> i have a StringBuilder buffering the input, and i try to create
> the XmlTextReader using a StringReader created from StringBuilder's
> ToString().
> 
> > You can create a NetworkStream from your Socket and use that to create
> > your XmlTextReader instance.  Then you just do a continuous Read() loop,
> > until EOF.
> 
> i can't, as the initial tag is only closed when the session is over.
> imagine something like this:
> 
> (connection starts)
> client: <?xml ...?><stream:stream ....>
> server: <?xml ...?><stream:stream ....>
> client: <auth info><.../></auth info>
> server: <some answer><.../></some answer>
> client: <comm1><.../></comm1>
> server: <some answer><.../></some answer>
> ...
> client: </stream:stream>
> server: </stream:stream>
> (connection terminates)
> 
> not a parser friendly communication ;)

That should be no problem.  Just create both an XmlTextReader and an
XmlTextWriter on the stream.  In your Read loop, you know where you are
in your stream, and can take action based on that.  In your example, if
the NodeType is XmlNodeType.Element, and the Name is "stream", then
write the beginning elements back to the client on the writer and
continue.  If the Name is "auth", then continue reading the input until
the NodeType is XmlNodeType.EndElement and the name is also "auth". 
(Along the way to EndElement you can get the data out of the node that
you're looking for.)  Then you can send your answer down the writer and
continue.  This is somewhat simplified explanation, but it should give
the general idea.

-- Scott

> 
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list