| 1 |
/* |
|---|
| 2 |
www.sourceforge.net/projects/tinyxpath |
|---|
| 3 |
Copyright (c) 2002-2004 Yves Berquin (yvesb@users.sourceforge.net) |
|---|
| 4 |
|
|---|
| 5 |
This software is provided 'as-is', without any express or implied |
|---|
| 6 |
warranty. In no event will the authors be held liable for any |
|---|
| 7 |
damages arising from the use of this software. |
|---|
| 8 |
|
|---|
| 9 |
Permission is granted to anyone to use this software for any |
|---|
| 10 |
purpose, including commercial applications, and to alter it and |
|---|
| 11 |
redistribute it freely, subject to the following restrictions: |
|---|
| 12 |
|
|---|
| 13 |
1. The origin of this software must not be misrepresented; you must |
|---|
| 14 |
not claim that you wrote the original software. If you use this |
|---|
| 15 |
software in a product, an acknowledgment in the product documentation |
|---|
| 16 |
would be appreciated but is not required. |
|---|
| 17 |
|
|---|
| 18 |
2. Altered source versions must be plainly marked as such, and |
|---|
| 19 |
must not be misrepresented as being the original software. |
|---|
| 20 |
|
|---|
| 21 |
3. This notice may not be removed or altered from any source |
|---|
| 22 |
distribution. |
|---|
| 23 |
*/ |
|---|
| 24 |
|
|---|
| 25 |
/** |
|---|
| 26 |
\file xml_util.h |
|---|
| 27 |
\author Yves Berquin |
|---|
| 28 |
*/ |
|---|
| 29 |
|
|---|
| 30 |
private import xpath.tinyxml; |
|---|
| 31 |
|
|---|
| 32 |
public { |
|---|
| 33 |
int i_xml_cardinality (TiXmlElement XEp_elem, bool o_by_name) |
|---|
| 34 |
in { assert (XEp_elem); } |
|---|
| 35 |
body |
|---|
| 36 |
{ |
|---|
| 37 |
|
|---|
| 38 |
TiXmlElement XEp_child; |
|---|
| 39 |
char[] S_name; |
|---|
| 40 |
int i_res; |
|---|
| 41 |
|
|---|
| 42 |
TiXmlNode XNp_parent = XEp_elem.Parent; |
|---|
| 43 |
if (o_by_name) |
|---|
| 44 |
{ |
|---|
| 45 |
S_name = XEp_elem.Value; |
|---|
| 46 |
XEp_child = XNp_parent.FirstChildElement(S_name); |
|---|
| 47 |
i_res = 1; |
|---|
| 48 |
while (XEp_child) |
|---|
| 49 |
{ |
|---|
| 50 |
if (XEp_child == XEp_elem) |
|---|
| 51 |
return i_res; |
|---|
| 52 |
else |
|---|
| 53 |
{ |
|---|
| 54 |
i_res++; |
|---|
| 55 |
XEp_child = XEp_child.NextSiblingElement (S_name); |
|---|
| 56 |
} |
|---|
| 57 |
} |
|---|
| 58 |
} |
|---|
| 59 |
else |
|---|
| 60 |
{ |
|---|
| 61 |
XEp_child = XNp_parent.FirstChildElement; |
|---|
| 62 |
i_res = 1; |
|---|
| 63 |
while (XEp_child) |
|---|
| 64 |
{ |
|---|
| 65 |
if (XEp_child == XEp_elem) |
|---|
| 66 |
return i_res; |
|---|
| 67 |
else |
|---|
| 68 |
{ |
|---|
| 69 |
i_res++; |
|---|
| 70 |
XEp_child = XEp_child.NextSiblingElement; |
|---|
| 71 |
} |
|---|
| 72 |
} |
|---|
| 73 |
} |
|---|
| 74 |
assert (false); |
|---|
| 75 |
return -1; |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
int i_xml_family_size (TiXmlElement XEp_elem) |
|---|
| 79 |
in { assert(XEp_elem); } |
|---|
| 80 |
body |
|---|
| 81 |
{ |
|---|
| 82 |
|
|---|
| 83 |
TiXmlElement XEp_child; |
|---|
| 84 |
int i_res; |
|---|
| 85 |
|
|---|
| 86 |
TiXmlNode XNp_parent = XEp_elem.Parent; |
|---|
| 87 |
XEp_child = XNp_parent.FirstChildElement; |
|---|
| 88 |
i_res = 0; |
|---|
| 89 |
while (XEp_child) |
|---|
| 90 |
{ |
|---|
| 91 |
i_res++; |
|---|
| 92 |
XEp_child = XEp_child.NextSiblingElement; |
|---|
| 93 |
} |
|---|
| 94 |
return i_res; |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
} |
|---|