selectsinglenode

XmlDocument.SelectSingleNode and xmlNamespace issue

北慕城南 提交于 2019-11-26 00:44:08
问题 I\'m loading a string to an XML document that contains the following structure : <?xml version=\"1.0\" encoding=\"utf-8\"?> <Project ToolsVersion=\"4.0\" DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\"> <ItemGroup> <Compile Include=\"clsWorker.cs\" /> </ItemGroup> </Project> then im loading all into xmldocument : XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(Xml); then the following problem occurs : XmlNode Node = xmldoc.SelectSingleNode(\"/

XmlDocument.SelectSingleNode and xmlNamespace issue

人盡茶涼 提交于 2019-11-25 19:39:02
I'm loading a string to an XML document that contains the following structure : <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <Compile Include="clsWorker.cs" /> </ItemGroup> </Project> then im loading all into xmldocument : XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(Xml); then the following problem occurs : XmlNode Node = xmldoc.SelectSingleNode("//Compile"); // return null when i remove the xmlns attribute from the root element(Project) its working fine, how can i