菜鸟问题:XML节点读取
<?xml version= "1.0 " encoding= "SHIFT_JIS "?>
<XMI xmi.version= "1.1 " xmlns:UML= "omg.org/UML1.3 " timestamp= "2007-08-03 09:35:54 ">
<XMI.header>
<XMI.documentation>
<XMI.exporter> Enterprise Architect </XMI.exporter>
<XMI.exporterVersion> 2.5 </XMI.exporterVersion>
</XMI.documentation>
</XMI.header>
<XMI.content>
<UML:Model name= "EA Model " xmi.id= "MX_EAID_4F3B848F_6DA7_48b5_BAB6_EC06006A896D ">
<UML:Namespace.ownedElement>
<UML:Class name= "EARootClass " xmi.id= "EAID_11111111_5487_4080_A7F4_41526CB0AA00 " isRoot= "true " isLeaf= "false " isAbstract= "false "/>
上面是XML文件的格式
我想用SelectNodes方法选择 "UML:Class "节点
为什么在执行SelectNodes方法的时候出错?
SelectNodes的参数应该怎样写?
xmlDoc = new XmlDocument();
xmlDoc.Load(fileName);
classNodeList = xmlDoc.SelectNodes( "UML:Class ");
------解决方案--------------------顶顶
------解决方案--------------------string patn = @ "e:\111.xml ";
XmlDocument doc = new XmlDocument();
doc.Load(patn);
XmlNamespaceManager xnm = new XmlNamespaceManager(doc.NameTable);
xnm.AddNamespace( "UML ", "omg.org/UML1.3 ");
XmlNode node = doc.SelectSingleNode( "/XMI/XMI.content/UML:Model/UML:Namespace.ownedElement/UML:Class ", xnm);
------解决方案--------------------xml查询带命名空间
--------------------
XmlDocument doc = new XmlDocument();
//doc.Load("C:\\nso.xml");
doc.Load("C:\\nso.xml");
NameTable xmt = new NameTable();
//xmt.Add("ns0");
XmlNamespaceManager xnm = new XmlNamespaceManager(xmt);
xnm.AddNamespace("ns0", "http://schemas.nbeport.gov.cn/H2KSubscription/DEC");
XmlNode node = doc.SelectSingleNode("//ns0:NewDataSet/ns0:ENTRY_WORKFLOW", xnm);
XmlNode node = doc1.SelectSingleNode("/NewDataSet/ENTRY_WORKFLOW[STEP_ID='70000000']/CREATE_DATE/text()");
string ser = node.Value;
//如果是默认命名空间,可以添加别名进行查询。
XmlDocument doc = new XmlDocument(