- Home /
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.
What's wrong with using the usage example Cameron presents on the forum post you link to? It just loads an X$$anonymous$$L file from the Resources folder, parses it, and then dumps the xml out from the data returned by the parsing.
With TinyX$$anonymous$$LReader I can execute code base on the currently open tag such as...
if (reader.tagName == "$$anonymous$$yTag") { num$$anonymous$$yTag++ }
But I don't understand how, using this parser, I can store information between tags into variables.
Answer by Waz · Jul 29, 2011 at 10:48 PM
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).
See the example at that link - it traverses the tree in order to write it back out as X$$anonymous$$L - quite a good test and example, I think. Once you've used the DO$$anonymous$$-style, you'll never want to go back.
It will output the entire X$$anonymous$$L to the console but how is that of use to me? Please provide a more contextual example. :(
For example, I have $$anonymous$$yNameIsBob in an X$$anonymous$$L 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?
Traversing a tree is a basic program$$anonymous$$g 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.
Your answer
![](https://koobas.hobune.stream/wayback/20220612162249im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Getting the position of all game objects with the same tag 1 Answer
Renderer on object disabled after level reload 1 Answer
Flip over an object (smooth transition) 3 Answers