XPath problem

M

Marina

Hi I have the following top most node:

<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.microsoft.com/MicrosoftNotificationServices/ApplicationDef
initionFileSchema">

....


</Application>

It has a bunch of other nodes inside. I am trying to use .NET and XPATH to
locate certain nodes. However, the xmlns attributes are getting in the way.
If I remove them, my SelectSingleNode calls work perfectly.

I have tried:

Dim xmlNamespace As New XmlNamespaceManager(adf.NameTable)
xmlNamespace.AddNamespace("",
"http://www.microsoft.com/MicrosoftNotificationServices/ApplicationDefinitio
nFileSchema")
xmlNamespace.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema")
xmlNamespace.AddNamespace("xsi", http://www.w3.org/2001/XMLSchema-instance)

Even a call such as:

myDoc.SelectSingleNode("Application", xmlNamespace)

fail as long as those attributes are there.

And then passing in the xmlNamespace object to the SelectSingleNode method,
but that's not working.

What is the correct way of dealing with this issue?

Thanks.
 
O

Oleg Tkachenko

Marina said:
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.microsoft.com/MicrosoftNotificationServices/ApplicationDef
initionFileSchema">

It has a bunch of other nodes inside. I am trying to use .NET and XPATH to
locate certain nodes. However, the xmlns attributes are getting in the way.
If I remove them, my SelectSingleNode calls work perfectly.

I have tried:

Dim xmlNamespace As New XmlNamespaceManager(adf.NameTable)
xmlNamespace.AddNamespace("",
"http://www.microsoft.com/MicrosoftNotificationServices/ApplicationDefinitio
nFileSchema")
xmlNamespace.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema")
xmlNamespace.AddNamespace("xsi", http://www.w3.org/2001/XMLSchema-instance)

Even a call such as:

myDoc.SelectSingleNode("Application", xmlNamespace)

fail as long as those attributes are there.

And then passing in the xmlNamespace object to the SelectSingleNode method,
but that's not working.

What is the correct way of dealing with this issue?

xmlNamespace.AddNamespace("foo",
"http://www.microsoft.com/MicrosoftNotificationServices/ApplicationDefinitionFileSchema")
myDoc.SelectSingleNode("foo:Application", xmlNamespace)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top