-
March 26th, 2014, 10:00 PM
#1
TiXmlElement (tinyxml), looking for ways to get "Next" Child?
Good Morning,
Code:
<a>
<b>b</b>
<c>c</c>
</a>
TiXmlElement* b = a->FirstChildElement();
TiXmlElement* c = b->NextSiblingElement();
How can I get "c" directly from "a", without prior knowledge of "b" in the middle
Like
TiXmlElement* c = a->NextChildElement(); which is not available in tinyxml
Any help is greatly appreciated!
Thanks
Jack
-
March 26th, 2014, 10:25 PM
#2
Re: TiXmlElement (tinyxml), looking for ways to get "Next" Child?
You could always write:
Code:
TiXmlElement* c = a->FirstChildElement()->NextSiblingElement();
-
March 26th, 2014, 10:46 PM
#3
Re: TiXmlElement (tinyxml), looking for ways to get "Next" Child?
Or a->FirstChild("c") if the schema is that rigid.
I prefer tinyxml2 myself.
gg
-
March 28th, 2014, 04:17 AM
#4
Re: TiXmlElement (tinyxml), looking for ways to get "Next" Child?
Thanks, I've got an additional question which is quite off-topic.
Code:
<Index id="0">0</Index>
<Index id="1">2</Index>
<Index id="2">1</Index>
If I want to represent this, not by ids, but a size number (of 3) followed by
3 numbers, what is the recommended way to represent this in xml?
Thanks
Jack
-
March 28th, 2014, 07:50 AM
#5
Re: TiXmlElement (tinyxml), looking for ways to get "Next" Child?
there is no "recommended" way if what you want to do it represent an array then there are various ways how you COULD do it, with each their advantages and disadvantages.
1) name the array and reuse it for items, using internal xml ordering as the index (= the collection of items is the array itself)
Code:
<MyArray>0</MyArray>
<MyArray>2</MyArray>
<MyArray>1</MyArray>
2) name the array, and enumerate the elements explicitely, using internal xml ordering as the index (=the collection is a container of nodes)
Code:
<MyArray>
<item>0</item>
<item>2</item>
<item>1</item>
</MyArray>
3) Either 1 or 2 with explicit index attributes (this is what you used in #4 applied to 1)).
This has the advantage over 1 and 2 that you are not dependant on the internal xml ordering and you can leave gaps in the index numbering. Either of which can be an advantage or disadvantage.
4) using indexed tags (applicable on the 1 or 2 method, though it's rare to see it used on 1)
Code:
<MyArray>
<item0>0</item0>
<item1>2</item1>
<item2>1</item2>
</MyArray>
5) using your own parsing on the item. (lets say a semiconol separated list of values)
Code:
<MyArray>0;2;1</MyArray>
6) ... Whatever other system works for you.
There's no 'right' or 'wrong' way to do things, I've seen all of the above being used. Each method has pro's and cons.
There is a growing trend in xml however (partly driven by xpath syntax, XSD syntax and xml tools) to view nodes in xml as containers for what's in side them. Given that paradigm, the typical solution for an array is given in 2) whereby you can create a definition for an item (which could be a simple type or a complex type), and then create a complextype for the array of that type of item.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|