Xpath on VS2005 file

J

Jeff Jarrell

I can't seem to get an xpath expression proper to get the references out of
the *.vbproj project file in VS2005.

the project is loaded into an XMLDocument

_dom = new xmldocument
_dom.load(pathToMyProjectFile)

dim myNodeList as XMLNodeList
myNodeList = _dom.selectNodes("some xpath expression that returns the
references"). ????

I have tried a lot of things but I just don't seem to get it. MyNodeList has
zero elements in it.

Thanks in advance,
jff
 
B

Bart Mermuys

Hi,

Jeff Jarrell said:
I can't seem to get an xpath expression proper to get the references out of
the *.vbproj project file in VS2005.

the project is loaded into an XMLDocument

_dom = new xmldocument
_dom.load(pathToMyProjectFile)

dim myNodeList as XMLNodeList
myNodeList = _dom.selectNodes("some xpath expression that returns the
references"). ????

After having a look at the vb project file (VB2005Express/VC2005Beta2), it
looks like the root node has a default namespace (see xmlns="..." ). A
default namespace applies to the element and all child elements. (Child
elements can override the default namespace though.)

The path as in XPath, must be fully qualified, even when a namespace is a
default one.

Dim xdoc As New XmlDocument
xdoc.Load(pathToMyProjectFile)

' get default namespace and create a prefix for it
Dim xmlnsmgr As New XmlNamespaceManager(xdoc.NameTable)
xmlnsmgr.AddNamespace("d", xdoc.DocumentElement.NamespaceURI)

Dim nodes As XmlNodeList =
xdoc.SelectNodes("/d:project/d:ItemGroup/d:Reference", xmlnsmgr)
For Each node As XmlNode In nodes
Console.WriteLine(node.Attributes("Include").Value)
Next

HTH,
Greetings
 
J

Jeff Jarrell

Aha... Thank you.

jeff

Bart Mermuys said:
Hi,



After having a look at the vb project file (VB2005Express/VC2005Beta2), it
looks like the root node has a default namespace (see xmlns="..." ). A
default namespace applies to the element and all child elements. (Child
elements can override the default namespace though.)

The path as in XPath, must be fully qualified, even when a namespace is a
default one.

Dim xdoc As New XmlDocument
xdoc.Load(pathToMyProjectFile)

' get default namespace and create a prefix for it
Dim xmlnsmgr As New XmlNamespaceManager(xdoc.NameTable)
xmlnsmgr.AddNamespace("d", xdoc.DocumentElement.NamespaceURI)

Dim nodes As XmlNodeList =
xdoc.SelectNodes("/d:project/d:ItemGroup/d:Reference", xmlnsmgr)
For Each node As XmlNode In nodes
Console.WriteLine(node.Attributes("Include").Value)
Next

HTH,
Greetings
 

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