xml parsing - Not able to parse XML in C# with default namespace -


i not able parse xml document default namespace.

if remove namespace xmlns="http://java.sun.com/xml/ns/j2ee xml file, able values in nodelist. don't want 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 - 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; } 

you should use xmlnamespacemanager in call

xmlnamespacemanager ns = new xmlnamespacemanager(docusers.nametable); ns.addnamespace("test", "http://java.sun.com/xml/ns/j2ee");   xmlnodelist nodelist = docusers.selectnodes("//test:display-name",ns); 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -