XML Parsing: How to parse 20-100kb of xml?
Started by samjones, Dec 25 2011 03:22 AM
7 replies to this topic
#1
Posted 25 December 2011 - 03:22 AM
Any guidance appreciated for this newb question!
I have a simple .net app, running on the desktop. I am using linq and xml.linq, so life is pretty good.
I want to run this on netduino, and need to figure out:
- How to parse the interesting elements from an xml response that is 20kb - 100kb in size
- How to do this every 60 seconds...
Any pointers greatly appreciated!
#2
Posted 25 December 2011 - 10:14 AM
Hello SamJones, and Happy Xmas, wherever you are.
I'd guess you won't able do that: consider that 100K is about the overall free RAM space of a Netduino space. Even supposing a complete parsing, you'd need enough space for the DOM...
Rather, you may consider some kind of binary serialization, which *should be* the most efficient way to exchange data. However, that could be a bit complex, but may solve your problem.
Cheers
Biggest fault of Netduino? It runs by electricity.
#3
Posted 25 December 2011 - 05:31 PM
One idea we had was to save the xml to the sd card, then parse through it sequentially... but I don't know if the netduino cpu can do this fast, or if it will take 30 seconds or something...
#4
Posted 25 December 2011 - 06:20 PM
The SD is a good idea, but to achieve a sequential parsing, you should use SAX, instead of DOM. This is not available, though.
At this point, the only way is to implement your own parser...just an overkill, but it may be worthwhile, maybe.
Cheers
At this point, the only way is to implement your own parser...just an overkill, but it may be worthwhile, maybe.
Cheers
Biggest fault of Netduino? It runs by electricity.
#5
Posted 25 December 2011 - 08:22 PM
Thanks. I am taking another route....
#6
Posted 25 December 2011 - 08:43 PM
This might be a crazy suggestion, but there is a JSON parser available: netduino.helpers.Helpers.JSONParser. As is, it wouldn't solve the OP's problem, but I wonder how hard it would be to modify it so that instead of building up a data structure of Hashtables and ArrayLists it would fire off SAX-type events to a ContentHandler? Maybe I'm kidding myself, but it looks like it might be easy.
I guess the result would be called "SAJ" (Simple API for JSON). Googling "SAJ Simple API for JSON" shows that at least one person has already done something like this for other platforms.
#7
Posted 25 December 2011 - 09:53 PM
Interesting!
I don't have control over the data format, and it is xml.
I am writing a web service to make the large xml response simple.
#8
Posted 26 December 2011 - 12:52 AM
Interesting!
I don't have control over the data format, and it is xml.
I am writing a web service to make the large xml response simple.
I think this is very much do-able on the Netduino. I have streamed individual files from the microSD card that were in excess of 300k. And I could have easily inspected the text of the chunks. You'll have to use streams and reasonably sized chunks and parse/inspect the file as text.
-Valkyrie-MT
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users