开发者

How to use short namespaces with XElements in .Net?

开发者 https://www.devze.com 2023-01-09 09:12 出处:网络
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 somethin

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消