How to use short namespaces with XElements in .Net?
I am parsing an XML (RDF specifically) document, basically mapping it to some strongly typed 开发者_开发百科objects in .Net. I have been using this really long syntax for selecting namespaces something like:
ontology.Elements("{http://www.w3.org/1999/02/22-rdf-syntax-ns#}Property")
What I really want to do is something like:
ontology.Elements("rdf:Property")
I know with the older XML framework there was a Namespace Manager you could map namespace short names to the URIs, but not sure how to do the same with XElements. Ideas?
Construct the namespace separately as an XNamespace
:
XNamespace rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
...
ontoloy.Elements(rdf + "Property");
I really like the way LINQ to XML handles namespaces, personally.
精彩评论