我想进入特定路径'/trace/calls/call/userTableParameters/parameter'并取出所有带有值的参数名称。在进行 xmlnode 选择时,我在 xpath 中使用了命名空间。它返回正确的第一个子节点“参数”。但 xmlnodelist 不会进一步返回任何内容。我的代码会出现什么问题?
XmlDocument doc = new XmlDocument();
doc.Load(@"d:\Drops.xml");
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("nsTrace", "http://www.polystar.com/OSIX/monitoring/traceSchemaV1.0");
XmlNode ParameterNode = doc.SelectSingleNode("//nsTrace:userTableParameters", nsmgr);
XmlNodeList ParameterNodeList = ParameterNode.SelectNodes("//parameter");
foreach (XmlNode node in ParameterNodeList)
{
Parameter drop = new Parameter();
drop.name = node.Attributes.GetNamedItem("name").Value;
drop.content = node.InnerText;
callParameter.ParameterList.Add(drop);
}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<trace xmlns="http://www.polystar.com/OSIX/monitoring/traceSchemaV1.0">
<calls>
<call>
<messages>
<message>
<parameters>
<parameter name="Timestamp">Wed 11 Nov 2015 11:58:14.096</parameter>
<parameter name="Direction">---></parameter>
<parameter name="Resulting Status">Normal</parameter>
<parameter name="Resulting State Name">AP Request Pending</parameter>
<parameter name="Source Address">11.111.111.11</parameter>
<parameter name="Dest Address">11.222.222.22; ABC2</parameter>
<parameter name="Media Probe Id"/>
<parameter name="Deciphered"/>
</parameters>
</message>
</messages>
<userTableParameters>
<parameter name="Start Time">11:58:14.096</parameter>
<parameter name="End Time">11:58:27.191</parameter>
<parameter name="Duration">00:00:13.095</parameter>
<parameter name="Date">Wed 11 Nov 2015</parameter>
<parameter name="Protocol">AP</parameter>
<parameter name="Status">End</parameter>
<parameter name="AP II"/>
<parameter name="AP TI">e0a5e84d'H</parameter>
<parameter name="AP Cause">3; due-to-generated-reason</parameter>
</userTableParameters>
</call>
</calls>
</trace>