Jump to content

Streaming XML Data

- - - - -

  • Please log in to reply
1 reply to this topic

#1
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts
I've got a hardware device that is sending data via a "version" of XML,
Each output is sent out about every 5ms.
I'm able to read & capture all the data without issue, but I'm trying to figure out the best way to Parse the data.
The XML parsers appear to not work for this data due to multiple root elements.
Example Raw Data from the Device
<cross-domain-policy>
   <allow-access-from domain="*" to-ports="*" />
</cross-domain-policy> <FAILSAFE>0</FAILSAFE> <KEY4>0</KEY4> <CATEGORYLIST>
   <BUTTONITEM INDEX="0" BTNIMG="btnimages/defaults/CG  CH2" FLEXIMG="1111">Device 1</BUTTONITEM>
   <BUTTONITEM INDEX="1" BTNIMG="btnimages/defaults/Clips  CH2" FLEXIMG="2222">Device 2</BUTTONITEM>
   <BUTTONITEM INDEX="2" BTNIMG="btnimages/defaults/Stills  CH2" FLEXIMG="3333">Device 3</BUTTONITEM>
</CATEGORYLIST> <SOURCEDEVICELIST>
Now Line 3 in this Example "</cross-domain-policy> <FAILSAFE>0</FAILSAFE> <KEY4>0</KEY4> <CATEGORYLIST>"

Has the close tag from Line 1, and then an Open Tag <CATEGORYLIST> that doesn't close tell line 7.
So if I try to parse it Line by line, I get errors.

Their is No End to this data, as it's streaming data that might run for hours on end.

What would be the best way to parse the data with XML, or should I drop trying to use any XML parser & just rewrite my own parser for this data from scratch ?

#2
zoranh

zoranh

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
.NET Framework has no support for stream of XML elements. There are third party libraries that do (ask Google). I had the same problem to solve at work and I have coded a simple stream myself (because my company doesn't support using third party code).

If you write your own code that separates XML elements, then read each of the elements using XmlReader. Make sure that XmlReader is created with XmlReaderSettings object's ConformanceLevel set to Fragment. That will do the work.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users