I am not able to parse XML document with a default namespace.
If I remove the namespace xmlns="http://java.sun.com/xml/ns/j2ee from the XML file, then I am able to get values in nodelist. I don't want to use Linq.
XML:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<display-name>Test - My tomcat webapp</display-name>
</web-app>
C# code:
String strFileUsers = @"E:\\Dot_net\\XML_Parser\\demo\\web_org.xml";
XmlDocument docUsers = new XmlDocument();
try
{
docUsers.Load(strFileUsers);
}
catch (Exception)
{
MessageBox.Show("Cannot open file ");
return;
}
try
{
XmlNodeList nodeList = docUsers.SelectNodes("//display-name");
Console.WriteLine(nodeList.Count);
}
catch (Exception ex)
{
return;
}