views:

22

answers:

1

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?

+1  A: 

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.

Jon Skeet
@Jon Cool, that helps - thanks Jon!
Paul Fryer