Forum Discussion

sdachepe's avatar
sdachepe
New Contributor
13 years ago

Unable to read xml child node, when parent node having two different child nodes.

Hi All,



I am facing one problem while reading the XML child node.



Using C# scripting in the Test complete.

My function is like below.




function doGetSpecificChildNodeFromKVX(childNode,nodeNumber)

{



  var xmlDoc, s;

  var actualPath="C:\\StorePos\\FILES\\HISTORY\\Testing.xml"

 

     flg=2000000;

      while(flg!=0)

      {                          

 

     if (aqFile["Exists"](actualPath)) 

       

      {

        break;

      }

       flg--;

      }

  // Specify your file name

  var FileName = actualPath;

 

  // Load xml file

  xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");

 

  xmlDoc.load(FileName);



  // Check errors

  if (xmlDoc.parseError.errorCode != 0)

  {

    s = "Reason: " + xmlDoc.parseError.reason + "\n" +

        "Line: " + xmlDoc.parseError.line + "\n" +

        "Text: " + xmlDoc.parseError.srcText;

    //Log.Error("Failed to open file " + FileName, s);

    return;

  }



  // Specify your XPath expression

  var xmlNode = xmlDoc.selectNodes("//"+childNode);

   Log["Message"](xmlNode);

  

  if (xmlNode != null)

{

  for (var i = 0; i < xmlNode["length"]; i++)

    //Log["Message"](xmlNode.item(i).text);

    var actual=xmlNode.item(nodeNumber).text;

    return actual;

     

}



}







XML file looks like below.



 <?xml version="1.0" encoding="utf-8" ?>

- <RBSReceipt Generator="StorePos" Version="1.0" CreationDate="2013-06-03" CreationTime="12:13:37">

<SaleItem trans_id="1000">

- <CommonData trans_id="0">

  <Workstationid>51</Workstationid>

  <Employeeid>qadmin</Employeeid>

  <Customersessiomid>387</Customersessiomid>

  <Corrsequencenbr>-1</Corrsequencenbr>

  </CommonData>

  <Priceintax>99900</Priceintax>

  <Priceextax>92500</Priceextax>

  <Taxcode>2</Taxcode>

  <Taxrate>80000</Taxrate>

  <Changepricereasoncode />

  <Changepricereasontext /> 

  </SaleItem>

- <DynamicPackage trans_id="1611">

- <CommonData trans_id="0">

  <Workstationid>51</Workstationid>

  <Employeeid>qadmin</Employeeid>

  <Customersessiomid>387</Customersessiomid>

  <Creator>915</Creator>

  <Functioninterrupted>0</Functioninterrupted>

  <Trainingmode>0</Trainingmode>

  <Corr>0</Corr>

  <Corrsequencenbr>-1</Corrsequencenbr>

  </CommonData>

  <Id>P1</Id>

  <TotalPrice>199800</TotalPrice>

  <Discount>40000</Discount>

  <DiscountType>1</DiscountType>

  </DynamicPackage>

</RBSReceipt>



Right now i want to retrive the "Id" value , which under the DynamicPackage node.

With above mentioned script i can retrieve the value if its like this.

if i give the Childnode as WorkStationid and node number as "1"..  After the Commondata node its not working.





Please help me to solve this.





 






No RepliesBe the first to reply