471,122 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,122 software developers and data experts.

Xpath on VS2005 file

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

Nov 27 '05 #1
2 1825
Hi,

"Jeff Jarrell" <jj************@yahoo.com> wrote in message
news:ef**************@TK2MSFTNGP14.phx.gbl...
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


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

Nov 27 '05 #2
Aha... Thank you.

jeff

"Bart Mermuys" <bm*************@hotmail.com> wrote in message
news:e9**************@TK2MSFTNGP11.phx.gbl...
Hi,

"Jeff Jarrell" <jj************@yahoo.com> wrote in message
news:ef**************@TK2MSFTNGP14.phx.gbl...
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


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


Nov 27 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Phoebian | last post: by
4 posts views Thread by Gismo | last post: by
3 posts views Thread by abcd_68 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.