I've below xml data file with two nodes having qty more than 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>
My Question here is how suppose I could display 2 child element value under each nodes by using XPathNavigator.
If let said I need to display dono and custcode in each line of iteration loop like example of dono="DM202422" and custcode="M15" under custname="A Company".
Can anyone help me to improve my below codes, it is simply display one child element and same element after I've to next child element.
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");
}
}
The outcome of wrong result :
DO No: DM202422
Customer Code : DM202422
The result I want:
DO No: DM202422
Customer Code : M15
Thanks in advance for anyone could solve my problem.
No comments:
Post a Comment