Given an XElement loaded with
var root = XElement.Load("foo.xml");
How can you enumerate the namespaces used in the XML file?
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.
There is nothing that gives you all the namespaces used directly, so you have to enumerate all elements and extract their namespaces:
This would give you only the namespaces that were used by elements in the document. If you want to list all namespaces that are declared in the document (even if they are not used or if they are used only by attributes), you would need to iterate the namespace declarations: