.Net Micro XML
Started by Patrick, Sep 15 2010 02:56 PM
4 replies to this topic
#1
Posted 15 September 2010 - 02:56 PM
I'm using kingpin2k's GPS parser and whenever I get a message, I'd like to store the readings from my sensors on my SD card. This works just fine.
I'm thinking that I'd like to store the readings as KML (Google Earth) format but I can't find any information on how to natively write XML in .Net Micro. I see that there are two references that support XML (System.XML and System.XMLLegacy) but when I add them, I don't see anything useful in writing an XML document - such as add node, get attribute, etc.
If it comes down to it I'll roll my own XML writer, but you know, trying not to reinvent wheels and all.
Thanks!
Patrick
I'm thinking that I'd like to store the readings as KML (Google Earth) format but I can't find any information on how to natively write XML in .Net Micro. I see that there are two references that support XML (System.XML and System.XMLLegacy) but when I add them, I don't see anything useful in writing an XML document - such as add node, get attribute, etc.
If it comes down to it I'll roll my own XML writer, but you know, trying not to reinvent wheels and all.
Thanks!
Patrick
#2
Posted 16 September 2010 - 03:40 AM
I ended up doing a quick and dirty solution for this one. Tested with 26,000+ writes to the SD card (16MB kml file) and it's all good for my purposes.
public static string writeHeader(string name, string date) { return "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n" + "\t<Document>\n" + "\t\t<name>" + name + "</name>\n" + "\t\t<date>" + date + "</date>\n"; } public static string writePlacemark(string name, string inTemp, string extTemp, string press, string xG, string yG, string zG, string gpsAlt, string gpsTrack, string gpsTime, string coordinates) { return "\t\t\t<Placemark>\n" + "\t\t\t\t<name>" + name + "</name>\n" + "\t\t\t\t<ExtendedData>\n" + "\t\t\t\t\t<Data name=\"internalTemp\">\n" + "\t\t\t\t\t\t<value>" + inTemp + "</value>\n" + "\t\t\t\t\t</Data>\n" + "\t\t\t\t\t<Data name=\"externalTemp\">\n" + "\t\t\t\t\t\t<value>" + extTemp + "</value>\n" + "\t\t\t\t\t</Data>\n" + "\t\t\t\t\t<Data name=\"pressure\">\n" + "\t\t\t\t\t\t<value>" + press + "</value>\n" + "\t\t\t\t\t</Data>\n" + "\t\t\t\t\t<Data name=\"xG\">\n" + "\t\t\t\t\t\t<value>" + xG + "</value>\n" + "\t\t\t\t\t</Data>\n" + "\t\t\t\t\t<Data name=\"yG\">\n" + "\t\t\t\t\t\t<value>" + yG + "</value>\n" + "\t\t\t\t\t</Data>\n" + "\t\t\t\t\t<Data name=\"zG\">\n" + "\t\t\t\t\t\t<value>" + zG + "</value>\n" + "\t\t\t\t\t</Data>\n" + "\t\t\t\t\t<Data name=\"gpsAltitude\">\n" + "\t\t\t\t\t\t<value>" + gpsAlt + "</value>\n" + "\t\t\t\t\t</Data>\n" + "\t\t\t\t\t<Data name=\"gpsTrack\">\n" + "\t\t\t\t\t\t<value>" + gpsTrack + "</value>\n" + "\t\t\t\t\t</Data>\n" + "\t\t\t\t\t<Data name=\"gpsTime\">\n" + "\t\t\t\t\t\t<value>" + gpsTime + "</value>\n" + "\t\t\t\t\t</Data>\n" + "\t\t\t\t</ExtendedData>\n" + "\t\t\t\t\t<Point>\n" + "\t\t\t\t\t\t<coordinates>" + coordinates + "</coordinates>\n" + "\t\t\t\t\t</Point>\n" + "\t\t\t</Placemark>\n"; } public static string writeFooter() { return "\t</Document>\n" + "</kml>"; }
#3
Posted 16 September 2010 - 03:42 AM
Hi Patrick,
I believe that the .NET MF team focused on building an XmlReader--but that XmlWriter is either (a) part of the big DPWS libraries or ( not implemented.
It would be a cool community project for sure.
In the meantime, it looks like you found a simple and good way to implement what you were looking for. Fantastic.
Chris
#4
Posted 16 September 2010 - 09:07 PM
I'd like to suggest an alternative to XML.
Instead of using XML, I normally format everything I can using JSON (at least in NETMF.) It is takes up less space than XML which means you could store more data in memory (both RAM and flash.) It also means you would be sending less data over the wire (Ethernet, XBee, etc.) compared to data formatted in XML.
I created a striped down version of the Json.NET library on CodePlex and only used the functionality I really needed.
Instead of using XML, I normally format everything I can using JSON (at least in NETMF.) It is takes up less space than XML which means you could store more data in memory (both RAM and flash.) It also means you would be sending less data over the wire (Ethernet, XBee, etc.) compared to data formatted in XML.
I created a striped down version of the Json.NET library on CodePlex and only used the functionality I really needed.
#5
Posted 17 September 2010 - 03:02 PM
Hi Patrick,
I believe that the .NET MF team focused on building an XmlReader--but that XmlWriter is either (a) part of the big DPWS libraries or ( not implemented.
It would be a cool community project for sure.
In the meantime, it looks like you found a simple and good way to implement what you were looking for. Fantastic.
Chris
For some projects, that would probably work well.
For this one... I think he'd then have to convert to XML later on...
~ Eric D. Burdo ~ http://brick-labs.com/
Today LED's, tomorrow, the world!!! Well, OK, maybe servos.
Today LED's, tomorrow, the world!!! Well, OK, maybe servos.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users