XPath select node with namespace

Peter picture Peter · Feb 11, 2009 · Viewed 65.4k times · Source

Its a .vbproj and looks like this

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <ProjectGuid>15a7ee82-9020-4fda-a7fb-85a61664692d</ProjectGuid>

all i want to get is the ProjectGuid but it does not work when a namespace is there...

 Dim xmlDoc As New XmlDocument()
 Dim filePath As String = Path.Combine(mDirectory, name + "\" + name + ".vbproj")
 xmlDoc.Load(filePath)
 Dim value As Object = xmlDoc.SelectNodes("/Project/PropertyGroup/ProjectGuid")

what can i do to fix this?

Answer

annakata picture annakata · Feb 11, 2009

I'd probably be inclined to go with Bartek's* namespace solution, but a general xpath solution is:

//*[local-name()='ProjectGuid']

**since Bartek's answer has disappeared, I recommend Teun's (which is actually more thorough)*