x


How do I use this XML reader?

I found a lightweight XML reader here which I would like to use over TinyXMLReader as it has the ability to parse attributes. The problem is that I have literally no idea how to use this parser. TinyXMLReader provided a working example but this doesn't provide anything.

So does anyone here have any experience with this particular script? If you do, please provide a simple example of how to use and I'm sure I'll quickly come to grasps with it.

Thanks.

more ▼

asked Jul 29 '11 at 09:14 PM

AaronG gravatar image

AaronG
261 16 18 22

What's wrong with using the usage example Cameron presents on the forum post you link to? It just loads an XML file from the Resources folder, parses it, and then dumps the xml out from the data returned by the parsing.

Jul 29 '11 at 09:41 PM Graham Dunnett ♦♦

With TinyXMLReader I can execute code base on the currently open tag such as...

if (reader.tagName == "MyTag") { numMyTag++ }

But I don't understand how, using this parser, I can store information between tags into variables.

Jul 29 '11 at 10:16 PM AaronG
(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

There are two basic types of XML parser: those that traverse the logical tree as they parse and those that build a tree which you then traverse at your leisure. This is of the latter kind. Generally this is easier and more powerful too. It's a DOM tree (sort of).

more ▼

answered Jul 29 '11 at 10:48 PM

Waz gravatar image

Waz
6.5k 22 33 71

But how would I then traverse the tree? :P

Jul 30 '11 at 11:51 AM AaronG

See the example at that link - it traverses the tree in order to write it back out as XML - quite a good test and example, I think. Once you've used the DOM-style, you'll never want to go back.

Jul 30 '11 at 12:11 PM Waz

It will output the entire XML to the console but how is that of use to me? Please provide a more contextual example. :(

For example, I have MyNameIsBob in an XML file between a tags called 'Name'. I load it up via the parser and want to store the value between those tags in a string variable.

How would I do this?

Jul 30 '11 at 01:36 PM AaronG

Perhaps you should stick with the reader you understand.

Jul 30 '11 at 08:40 PM Waz

Traversing a tree is a basic programming concept. You walk from node to node, look at each node to decide wether to go into it's substructure. In your case, you look for the Name node.

Jul 30 '11 at 08:43 PM Waz
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4173
x256

asked: Jul 29 '11 at 09:14 PM

Seen: 1995 times

Last Updated: Jul 30 '11 at 08:43 PM