Is there a simple way, to get all nodes from an xml document? I need every single node, childnode and so on, to check if they have certain attributes.
Or will I have to crawl through the document, asking for childnodes?
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.
In LINQ to XML it’s extremely easy:
So to find all elements with a particular attribute, for example:
That’s assuming you wanted all elements. If you want all nodes (including text nodes etc, but not including attributes as separate nodes) you’d use
DescendantNodes()instead.EDIT: Namespaces in LINQ to XML are nice. You’d use:
or for a different namespace: