Forum Discussion

vinodkumar_chau's avatar
vinodkumar_chau
Contributor
10 years ago

reading xml using selectSingleNode()

Hi All ,

 

How should i read the below xml using selectSingleNode().I have to take name as input i.e configuration name="MarkXX_Gas_1.22_Fwd_Win7" as input and then read the values. The function should be able to read multiple tag names.

 

<?xml version="1.0"?>
<configurations>
 <configuration name="MarkXX_Gas_1.22_Fwd_Win7" OSName="Win7" OSServicePack="Service Pack 1" Windows64bit="True" OfficeVersion="2010" OfficeServicePack="SP1" UserAccountType="Domain" Locale="en-US" IEVersion="10.0.9200.17267">
  <meters>
      <meter Name="Meter1" ProductType="0" DeviceNumber="3414" FlowDirection="1" CPUBdSwVer="1.22-Gas_Sp3pt02_Eval-20150521_0725 2015/05/21" IPAddress="10.129.194.184" ConnectionType="0" />
   </meters>
 </configuration>

</configurations>

 

  • try something like this.....you may hav to debug this code...

     

    doc = Sys.OleObject("Msxml2.DOMDocument.6.0");
    doc.async = false;
    doc.load(docPath);
    if(doc.parseError.errorCode != 0)
              { s = "Reason:\t" + doc.parseError.reason + "\n" +
               "Line:\t" + aqConvert.VarToStr(doc.parseError.line) + "\n" +
               "Pos:\t" + aqConvert.VarToStr(doc.parseError.linePos) + "\n" +
               "Source:\t" + doc.parseError.srcText;
               Log.Error("Cannot parse the document.", s);
               return; }
    strNode = "name = MarkXX_Gas_1.22_Fwd_Win7";
    Node = doc.selectSingleNode(strNode);
    childNodes = Node.childNodes;
    //Log.Message(childNodes.length);
    for(i=0;i<childNodes.length-1;i++){ //
    Log.Message (Node.childNodes.item(i).text);

     

  • NisHera's avatar
    NisHera
    Valued Contributor

    try something like this.....you may hav to debug this code...

     

    doc = Sys.OleObject("Msxml2.DOMDocument.6.0");
    doc.async = false;
    doc.load(docPath);
    if(doc.parseError.errorCode != 0)
              { s = "Reason:\t" + doc.parseError.reason + "\n" +
               "Line:\t" + aqConvert.VarToStr(doc.parseError.line) + "\n" +
               "Pos:\t" + aqConvert.VarToStr(doc.parseError.linePos) + "\n" +
               "Source:\t" + doc.parseError.srcText;
               Log.Error("Cannot parse the document.", s);
               return; }
    strNode = "name = MarkXX_Gas_1.22_Fwd_Win7";
    Node = doc.selectSingleNode(strNode);
    childNodes = Node.childNodes;
    //Log.Message(childNodes.length);
    for(i=0;i<childNodes.length-1;i++){ //
    Log.Message (Node.childNodes.item(i).text);

     

    • vinodkumar_chau's avatar
      vinodkumar_chau
      Contributor

      Hi NisHera ,

       

      Thanks for the reply.The function will get attribute name value (MarkXX_Gas_1.22_Fwd_Win7) using project variable . using that value select the configuration whose attribute name value is similiar to passed value and then read all other attribute values.
      after that read the child node Meters and its sub child and attribute values. 

      I have to specifically use selectSingleNode().