I have some XML that looks like this:
<contacts>
<person>
<name>Bob</name>
<phoneNumber>1234</phoneNumber>
<mobileNumber>5678</mobileNumber>
<address>Address 1</address>
</person>
<person>
<name>Sue</name>
<phoneNumber>4321</phoneNumber>
<address>Address 2</address>
</person>
</contacts>
And some Xpath that queries for all the child nodes of <person>
:
//name | //phoneNumber | //mobileNumber | //address
The result is this:
Bob
1234
5678
Address 1
Sue
4321
Address 2
I would like the Xpath query to return something (a string?) so that I can identify which <person>
is missing a child node (in this case the second person has no <mobileNumber>
.
The output I would like would look something like this:
Bob
1234
5678
Address 1
Sue
4321
null
Address 2
Thanks and let me know if you need more details!
UPDATE
The expression must be valid for Xpath 1.0 as I am using javascript's document.evaluate
.
UPDATE
I have got some of the way with this expression:
concat(substring(/contacts/person/mobileNumber, 1 div boolean(/contacts/person/mobileNumber)),substring('null', 1 div not(/contacts/person/mobileNumber)))
However it now only evaluates the first <person>
and returns nothing for the second. Any suggestions?