Append xml1 as element in xml2 at specified path

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pruthvi888
    New Member
    • Mar 2007
    • 1

    Append xml1 as element in xml2 at specified path

    Hi i have 2 xmls
    xml1=
    <ABRQ>
    <HDR></HDR>
    <REQUEST>
    </REQUEST>
    </ABRQ>

    XML2=
    <CONTRACT>
    <ID/>
    <NUMBER/>
    <OWNER/>
    </CONTRACT>

    i want xml2 to be an element in xml1 . the result should be

    <ABRQ>
    <HDR></HDR>
    <REQUEST>
    <CONTRACT>
    <ID/>
    <NUMBER/>
    <OWNER/>
    </CONTRACT>
    </REQUEST>
    </ABRQ>
    please use VBSCRIPT commands as the QTP testing tool uses vbscript only.
  • dorinbogdan
    Recognized Expert Contributor
    • Feb 2007
    • 839

    #2
    I wrote a sample using vbscript, just to ilustrate the XMLDOM usage.
    Save the code in a file as .htm and run it in IE:
    [html]
    <html>
    <head>
    <script type="text/vbscript">
    sub vbtest()
    dim xml1, xml2, req, el
    Set xml1 = CreateObject("M icrosoft.XMLDOM ")
    Set xml2 = CreateObject("M icrosoft.XMLDOM ")
    xml1.loadXML document.getEle mentById("area1 ").value
    xml2.loadXML document.getEle mentById("area2 ").value
    set req = xml1.selectSing leNode("/ABRQ/REQUEST")
    set el = xml1.createElem ent("CONTRACT")
    req.appendChild xml2.selectSing leNode("/CONTRACT")
    document.getEle mentById("area" ).value = xml1.xml
    end sub
    </script>
    </head>
    <body>
    <textarea id="area1" rows = "10" cols ="30">
    <ABRQ>
    <HDR></HDR>
    <REQUEST>
    </REQUEST>
    </ABRQ>
    </textarea>
    <textarea id="area2" rows = "10" cols ="30">
    <CONTRACT>
    <ID/>
    <NUMBER/>
    <OWNER/>
    </CONTRACT>
    </textarea>
    <br>
    <br>
    <input type="button" value="Get XML result" onclick="vbtest ()">
    <br>
    <br>

    <textarea id="area" rows = "10" cols ="50"></textarea>

    </body>
    </html>
    [/html]

    Comment

    • dorinbogdan
      Recognized Expert Contributor
      • Feb 2007
      • 839

      #3
      Hi,
      Did you succeed to solve the problem ?
      If yes, please let me know, in order to close the thread.
      Thanks,
      Dorin.

      Comment

      Working...