I have to parse XML files (.gpx in my case) and I don't want to invent the wheel again.
If I'm not totally wrong, .NET CF has the XmlReader and XmlWriter classes for simple reading and writing of XML files.
If so, would it be hard to write a wrapper dll for this classes? I have no experience with writing dlls so please can someone give me some hints (or even better write such a dll :-) )? agraham?
I think your suggestion is an interesting one. However, if you need something to get you going now I have written some functions based on RegEx that extract XML Elements and Attributes. Let me know if you would like the code.
I know nothing about XML, all the terms are confusing to me, but after a bit of hacking around this sort of seems to do something that looks a bit like XML. Needs .NET 2.0.
A bit more stuff that looked like it might be useful in the dll and a rudimentary help file mostly cribbed from MSDN. I hope you all understand it - I don't
Thank you very much. I was just reading the threads which explain how to compile dlls with SharpDevelop when I saw your posts.
The Reader needs the ability to parse Attributes. Therefore it needs at least the MoveToNextAttribute Method. Then you can walk through the Attributes in your example:
Is it possible to predefine constants for the values in rdr.NodeType? Normally they are defined in Xml.XmlNodeType.xxx so you can create a Select statement with something like
Code:
Select rdr.NodeType Case cXmlNodeTypeText ... Case cXmlNodeTypeElement ... EndSelect
The help file does not work. I only get the message "The page cannot be displayed".
Ah good! Somebody seems to know what this XML stuff is all about.
Quote:
Originally Posted by corwin42
The Reader needs the ability to parse Attributes. Therefore it needs at least the MoveToNextAttribute Method. Then you can walk through the Attributes in your example
OK. So you at least want MoveToNextAttribute. Anything else that could be useful?
Quote:
Is it possible to predefine constants for the values in rdr.NodeType? Normally they are defined in Xml.XmlNodeType.xxx so you can create a Select statement
I am returning the XmlNodeType enum as strings as (once you get the help working) detailed in the help topic "Node types" so you can do
The help file does not work. I only get the message "The page cannot be displayed".
Works fine here, it's no different to my many other help files, all written off the same template. Are you running Vista? I had a similar problem recently with Erels help for GPSDriver - turned out Vista security had blocked it as it was an Internet download and I had to Right-click -> Properties -> Unblock to get it to work.
I have just converted my XML reader to use Andrew's DLL and it works fine. Maybe I am not understanding your request, but I don't think the DLL needs the MoveToNextAttribute method. The main loop returns each element in turn. As an element is found, the Item method will give you whatever attribute within the element that you require.
Code:
Do If (rdr.NodeType = "Element") AND (rdr.Name = "Book") Then bookdate = rdr.Item("Date") ElseIf (rdr.NodeType = "Element") AND (rdr.Name = "Chapter") Then chap.nbr = rdr.Item("Number") chap.name = rdr.Item("Name") chap.date = rdr.Item("Date") ElseIf (rdr.NodeType = "Element") AND (rdr.Name = "section") Then ..... etc..... EndIf LoopUntil rdr.Read = False
By the way, using the DLL is 3 times faster than my old RegEx-based code :-)
Well done Andrew!
Maybe I am not understanding your request, but I don't think the DLL needs the MoveToNextAttribute method. The main loop returns each element in turn. As an element is found, the Item method will give you whatever attribute within the element that you require.
Yes, but if I don't know the name of the attribute I can't access it with .Item. There should be a Method to walk through all attributes.
But there was still a mistake in my example code. The "If rdr.AttributeCount ... End If" block must be below the "msg = msg & rdr.NodeType & ": " rdr.Name & " " & rdr.Value & CRLF" line.
@agraham:
I think with the MoveToNextAttribute we have erverything to parse any xml-File. The writer works for simple XML-Files and thats enough for me. If you supply the source of the dll I will try to get it compiled with SharpDevelop and if I need additional methods I can write them by my own.
The help file works on my PC at work. Seems to be really a security problem because when I want to open it on my home PC WindowsXP asks if I really will open it.
Thank you very much.
I think this library will help many B4PPC users parsing xml files.