I have an xml:
<Customer id="">
<Name />
<Address />
</Customer>
I would like to select ONLY a root node with its attributes without its child nodes:
<Customer id=""/ >
Is such thing possible with XPath?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, this is not possible in XPath.
You can’t select the node without its children, because without its children it would be a different node, hence you would not be selecting a node from the original document.
To create the output you want you need to use a language which allows you to create new nodes, so you can’t do it in XPath. You can use XQuery to create new nodes, this should work: