xmldocument

Read XML Attribute using XmlDocument

二次信任 提交于 2019-11-25 21:41:06
How can I read an XML attribute using C#'s XmlDocument? I have an XML file which looks somewhat like this: <?xml version="1.0" encoding="utf-8" ?> <MyConfiguration xmlns="http://tempuri.org/myOwnSchema.xsd" SuperNumber="1" SuperString="whipcream"> <Other stuff /> </MyConfiguration> How would I read the XML attributes SuperNumber and SuperString? Currently I'm using XmlDocument, and I get the values in between using XmlDocument's GetElementsByTagName() and that works really well. I just can't figure out how to get the attributes? Arsen Mkrtchyan XmlNodeList elemList = doc.GetElementsByTagName(.

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