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.

XML library

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-21-2008, 09:03 AM
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 XML library

The XML library provides an XMLReader object that can read XML data from a suitably formatted file and an XMLWriter object that can write XML data to a file. Actually these objects are thin wrappers that expose the .NET XmlReader and XmlWriter classes to Basic4ppc. This library requires .NET 2.0 or later.

There is a (sort of - I don't really understand XML) demo, help and source for merging in the archive. If anyone who understands XML needs more functionality then post here and I will try to add it. If you can reference the MSDN docs on XMLReader XmlReader Members (System.Xml) and XmlWriter Members (System.Xml) then that would be useful.

EDIT :- Rapid update to version 1.1 with ReadString added to XMLReader and WriteCData added to XMLWriter as suggested by DaveW and corwin42. Thanks to both.

EDIT:- Version 1.2 posted with some additional navigational methods exposed for XmlReader See post #13.

EDIT:- Version 2.0 posted with some additional overloads for XmlWriter.WriteStartElement exposed and new XmlDocument and XmlNode objects. The XmlDocumentDemo uses StringBuilder from my http://www.basic4ppc.com/forum/addit...html#post10957 See posts #24 and #25

EDIT:- Minor update to version 2.1. See post#27

EDIT:- Updated to version 2.2. See post #33.

EDIT:- Updated to version 2.3. See post #39.

EDIT:- Updated to version 2.4. See post #43.

EDIT:- Updated to version 2.5. See post #59.

EDIT:- Updated to version 2.6. See post #61.
Attached Files
File Type: zip XML2.6.zip (36.9 KB, 258 views)

Last edited by agraham : 01-14-2010 at 01:12 PM.
Reply With Quote
  #2 (permalink)  
Old 11-21-2008, 01:10 PM
Knows the basics
 
Join Date: Jun 2008
Location: Barneveld, NL
Posts: 78
Default

Hi Andrew,

Something odd happened overnight with the XMLReader! When I first started playing with it, for NodeType: Element, rdr.Value returned the text content of the element. I *know* it did, I have the code here and was loading text from XML files quite happily!

But this morning that no longer works. Did you change that in v0.2? Now the rdr.Value only returns the text when the NodeType is Text. The trouble with that is you don't know what element that text came from (rdr.name is empty).

I had a look at the MSDN docs and there is a method called ReadString which (I think) does return the text when the NodeType is Element. Would it be possible to add that to the DLL?

XmlReader.ReadString Method (System.Xml)

Regards,
David.
Reply With Quote
  #3 (permalink)  
Old 11-21-2008, 02: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

Quote:
Originally Posted by DaveW View Post
When I first started playing with it, for NodeType: Element, rdr.Value returned the text content of the element. ... Did you change that in v0.2?
No, I haven't changed anything. Actually there is little to change as the Basic4ppc XMLReader object just calls the same named methods of the .NET XmlReader class (I don't believe in making things complicated ). If you look in the help, and the MSDN docs, under Value it appears to be documented that it would return an empty string for "Element". According to that only nine of the node types will return a value and "Element" is not one of them.


Quote:
Now the rdr.Value only returns the text when the NodeType is Text. The trouble with that is you don't know what element that text came from
As an XML document is a tree structure I assume you could track the current element using "Element" to stack the current element and "EndElement" to unstack it and revert to the previous element.


I'll add ReadString anyway, perhaps corwin42/Markus can comment!
Reply With Quote
  #4 (permalink)  
Old 11-21-2008, 02:56 PM
Knows the basics
 
Join Date: Jun 2008
Location: Barneveld, NL
Posts: 78
Default

It is really very odd! I know you did not change anything - or take anything out - but I also know that last night it was working and today it did not Anyway I have made some simple changes so that now it does work. Thanks anyway!

David.
Reply With Quote
  #5 (permalink)  
Old 11-21-2008, 03:26 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

It is not absolutely necessary to have the ReadString() method if you stack the elements as agraham explained but it will make things a bit easier. So it would be a good idea to implement it. The writer has the WriteString() method so perhaps the reader really should have ReadString().

Addidionally I will suggest to implement WriteCData() method to create CDATA Blocks. I don't really need it but it makes the writer more complete.

Greetings,
Markus
Reply With Quote
  #6 (permalink)  
Old 11-21-2008, 03:55 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

Quote:
Originally Posted by corwin42 View Post
ReadString() method ... it will make things a bit easier. So it would be a good idea to implement it ... I will suggest to implement WriteCData()
Both now done, thanks guys.
Reply With Quote
  #7 (permalink)  
Old 12-01-2008, 01:14 PM
Knows the basics
 
Join Date: Jan 2008
Posts: 64
Default

Hello, agraham. In my prog i need to send a XML string to server and then get a response (XML too). Can it be done with this lib? Not to save into file, just get the xml string to send it and then not to open a file, just parse the response string.
Reply With Quote
  #8 (permalink)  
Old 12-01-2008, 02:26 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'm afraid that this library only reads from, and writes to, files.
Reply With Quote
  #9 (permalink)  
Old 12-01-2008, 03:25 PM
Knows the basics
 
Join Date: Jan 2008
Posts: 64
Default

Quote:
Originally Posted by agraham View Post
I'm afraid that this library only reads from, and writes to, files.
And there is no way to do this as simple and convenient as it can be done with this lib?
Reply With Quote
  #10 (permalink)  
Old 12-01-2008, 04:05 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

Quote:
Originally Posted by Elrick View Post
And there is no way to do this as simple and convenient as it can be done with this lib?
In a nutshell - No!
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
Door library (Beta) - Special library Erel Official Updates 60 01-13-2011 11:23 AM
Merging Outlook library and Phone library Erel Official Updates 11 09-15-2010 09:22 AM
PhoneticAlgorithms Library (ex-StringComparison Library) moster67 Additional Libraries 10 11-11-2008 07:46 PM


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


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