我在 xml 数据文件下面有两个节点的数量超过 100,
<DO>
<delivery>
<dono>DM202422</dono>
<custcode>M15</custcode>
<custname>A Company</custname>
<stockcode>ZPP56012303001</stockcode>
<stockdesc>56012303001 DUPLEX PTD BOX</stockdesc>
<unitprice>2.1900</unitprice>
<qty>500</qty>
<amount>1095.00</amount>
</delivery>
<delivery>
<dono>DM202432</dono>
<custcode>M23</custcode>
<custname>B Company</custname>
<stockcode>ZPP5605855V16</stockcode>
<stockdesc>5605855 V16 PLAIN BOX</stockdesc>
<unitprice>0.1000</unitprice>
<qty>2000</qty>
<amount>200.00</amount>
</delivery>
</DO>
我的问题是如何假设我可以使用 XPathNavigator 在每个节点下显示 2 个子元素值。
如果说我需要在迭代循环的每一行中显示 dono 和 custcode,例如 custname="A Company" 下的 dono="DM202422" 和 custcode="M15" 示例。
谁能帮我改进下面的代码,它只是在我进入下一个子元素后显示一个子元素和相同的元素。
void queryinxpath()
{
System::Xml::XPath::XPathDocument^ doc = gcnew System::Xml::XPath::XPathDocument("C:/test.xml");
System::Xml::XPath::XPathNavigator^ nav = doc->CreateNavigator();
System::Xml::XPath::XPathExpression^ expr = nav->Compile("descendant::delivery[amount > 100]");
System::Xml::XPath::XPathNodeIterator^ iterator=nav->Select(expr);
while (iterator->MoveNext())
{
System::Xml::XPath::XPathNavigator^ nav_ = iterator->Current->Clone();
nav_->MoveToChild("dono","");
System::Console::WriteLine("DO No: {0} ",nav_->Value);
nav_->MoveToChild("custcode","");
System::Console::WriteLine("Customer Code : {0} ",nav_->Value);
System::Console::WriteLine("\n");
}
}
错误结果的结果:
编号:DM202422
客户编号:DM202422
我想要的结果:
编号:DM202422
客户代码:M15
提前感谢任何人都可以解决我的问题。