How can I determine the number of
"unknown" fields there are?
This XPath expression:
count(/*/*/*)
evalutes to the count of the elements, that a re children of the elements that are children of the top node of the XML document -- exactly what is wanted in this case.
If the "Row"
element can have children whose name does not start with "UnknownCol",
then this XPath expression provides the count of elements, whose name starts with "UnknownCol", and that are children of elements that are children of the top element:
count(/*/*/*[starts-with(name(), "UnknownCol")])
In case the top element may have other children than "Row"
, then an XPath expression giving the required count is:
count(/*/Row/*[starts-with(name(), "UnknownCol")])
Also, how can I read the attributes,
if any, for the unknown fields?
By knowing XPath :)
/*/Row/*[starts-with(name(), "UnknownCol")]/@*
selects all the attributes of all "UnknownCol"{String} elements
This XPath expression gives us the number of these attributes:
count(/*/Row/*[starts-with(name(), "UnknownCol")]/@*)
This Xpath expression gives us the name of the k-th such attribute ($ind must be set to the number k):
name( (/*/Row/*[starts-with(name(), "UnknownCol")]/@*)[$ind] )
And finally, this XPath expression produces the value of the k-th such attribute:
string( (/*/Row/*[starts-with(name(), "UnknownCol")]/@*)[$ind] )
Edit: The OP commented that he completely doesn't lnow the names of the children element.
The fix is easy: simply remove the predicate from all expressions:
count(/*/*/*)
count(/*/Row/*)
/*/Row/*/@*
count(/*/Row/*/@*)
name( (/*/Row/*/@*)[$ind] )
string( (/*/Row/*/@*)[$ind] )