Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Code Samples & Tips > Additional Libraries
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Additional Libraries Users contributed libraries.
This sub-forum is only available to licensed users.

wrapper for XmlReader and XmlWriter?

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-20-2008, 06:59 AM
Basic4ppc Expert
 
Join Date: Jul 2008
Location: Borchen, Germany
Posts: 571
Send a message via Skype™ to corwin42
Awards Showcase
Beta Tester 
Total Awards: 1
Default wrapper for XmlReader and XmlWriter?

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?

Thanks very much,
Markus
Reply With Quote
  #2 (permalink)  
Old 11-20-2008, 07:53 AM
Knows the basics
 
Join Date: Jun 2008
Location: Barneveld, NL
Posts: 78
Default

Hi Markus,

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.

David.
Reply With Quote
  #3 (permalink)  
Old 11-20-2008, 01:12 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

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.

Have a look, if you can understand what you need then I can add it, particularly if you can reference the MSDN docs on XMLReader XmlReader Members (System.Xml) and XMLWriter XmlWriter Members (System.Xml)
Attached Files
File Type: zip XML0.1.zip (2.9 KB, 16 views)
Reply With Quote
  #4 (permalink)  
Old 11-20-2008, 02:46 PM
Knows the basics
 
Join Date: Jun 2008
Location: Barneveld, NL
Posts: 78
Thumbs up

Andrew,

As always you are amazing! does not even begin to cover it!

I have run your little test and it seems to work, I will try to replace my existing code with your dll to see how it works in the real world.

David.
Reply With Quote
  #5 (permalink)  
Old 11-20-2008, 04:23 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

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
Attached Files
File Type: zip XML0.2.zip (13.6 KB, 24 views)
Reply With Quote
  #6 (permalink)  
Old 11-20-2008, 08:53 PM
Basic4ppc Expert
 
Join Date: Jul 2008
Location: Borchen, Germany
Posts: 571
Send a message via Skype™ to corwin42
Awards Showcase
Beta Tester 
Total Awards: 1
Default

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:

Code:
Sub ReadXML
   rdr.Open(AppPath & 
"\test.xml")    
   rdr.Read
   
Do
      
If rdr.AttributeCount > 0 Then
         
Do While rdr.MoveToNextAttribute
            msg = msg & 
"AttribName: " & rdr.Name & " AttribValue: " & rdr.Value & CRLF
         
Loop
      
End If
      msg = msg & rdr.NodeType  & 
"" rdr.Name & " " & rdr.Value & CRLF
   
Loop Until rdr.Read = False
   
Msgbox(msg)
End Sub
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
      ...
End Select
The help file does not work. I only get the message "The page cannot be displayed".

Greetings and many thanks,
Markus
Reply With Quote
  #7 (permalink)  
Old 11-20-2008, 10:00 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Ah good! Somebody seems to know what this XML stuff is all about.
Quote:
Originally Posted by corwin42 View Post
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
Code:
Select rdr.NodeType
   
Case "Text"
      ...
   
Case "Element"
      ...
End Select
Quote:
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.
Reply With Quote
  #8 (permalink)  
Old 11-20-2008, 10:44 PM
Knows the basics
 
Join Date: Jun 2008
Location: Barneveld, NL
Posts: 78
Default

Hi Corwin,

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")
Else If (rdr.NodeType = "Element"AND (rdr.Name = "Chapter"Then
    chap.nbr = rdr.Item(
"Number")
    chap.name = rdr.Item(
"Name")
    chap.date = rdr.Item(
"Date")
Else If (rdr.NodeType = "Element"AND (rdr.Name = "section"Then
           ..... etc.....
End If
Loop Until rdr.Read = False
By the way, using the DLL is 3 times faster than my old RegEx-based code :-)
Well done Andrew!

Last edited by DaveW : 11-20-2008 at 10:49 PM.
Reply With Quote
  #9 (permalink)  
Old 11-20-2008, 10:47 PM
Knows the basics
 
Join Date: Jun 2008
Location: Barneveld, NL
Posts: 78
Default

Andrew, Just saw you had replied while I was putting my reply together.:-)

The help works for me (though I think that in the Reader section the NodeType list should be under NodeType, not Name).

Again, thanks for a great job
Reply With Quote
  #10 (permalink)  
Old 11-21-2008, 06:19 AM
Basic4ppc Expert
 
Join Date: Jul 2008
Location: Borchen, Germany
Posts: 571
Send a message via Skype™ to corwin42
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by DaveW View Post
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.

Greetings,
Markus
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
New Hekkus Sound Library Wrapper! Louis Additional Libraries 21 04-23-2011 11:17 PM
Hekkus Sound System wrapper Louis Additional Libraries 18 09-27-2007 12:35 PM


All times are GMT. The time now is 06:37 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0