I have no problem using linq to xml to query xml but I have this special xml file whose first node starts with a declaration. If there was no declation ( ex: xmlns:dm0=”http://schemas.microsoft.com/VisualStudio/2008/DslTools/Core”)
I just use decandents to start querying data. My question is how to query xml ex: get the value of ‘forbiddenNamespaceDependencies’ with the following format:
<?xml version="1.0" encoding="utf-8"?>
<layerModel xmlns:dm0="http://schemas.microsoft.com/VisualStudio/2008/DslTools/Core">
<layers>
<layer Id="6c1b89f1-9204-4914-a721" name="Layer1" forbiddenNamespaceDependencies="NameSpace1">
<references>...
I don’t see what the problem is. I took your snippet and added closing tags to get a well-formed XML document looking like this:
Then the following C# code
outputs the value of the “forbiddenNamespaceDependencies” attribute just fine, the namespace declaration on the root element does not matter as no elements or attributes in your sample are in that namespace.
If you still have problems then consider to post enough details allowing us to reproduce the problem.