Highlighted
Micro Focus Contributor
Micro Focus Contributor
691 views

Appending XML using UFT

I currently have an issue with placing the node of a tag into an XML file

The script that i currently have is as follows:-

'----------------------------------------
'XML Test 2
'----------------------------------------
set xml_doc = createObject("Microsoft.XMLDOM")
xml_doc.async = false
xml_doc.load("C:\Temp\UnzipTestAttachments\MMS-CREATE-INDB-INDB9404-02082016-646624-INP.xml")

set root = xml_doc.documentElement
set new_MndtId = xml_doc.createNode(1, "MndtId", "")
set MndtId_text = xml_doc.createNode(3, "", "")
MndtId_text.text = "INDB097987464664646"
new_MndtId.appendChild(MndtId_text)

root.insertBefore new_MndtId, root.childNodes.item(1)
xml_doc.save("C:\Temp\UnzipTestAttachments\MMS-CREATE-INDB-INDB9404-02082016-646624-INPb.xml")

set MndtId = xml_doc.getElementsByTagName("MndtId")
n_MndtId = MndtId.length

for i=0 to n_MndtId-1
msgbox MndtId(i).text
next

Now when the documentElement has the following in the xml

<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.009.001.01">

It places the the tag that I need towards the end of the xml file

I actually require to appended/add a new tag to be placed after the <Mndt> tag (see attachment - MMS-CREATE-INDB-INDB9404-02082016-646624-INP.xml.jpg)

Could someone shed some light into how i would go abouts achieving this?

Tags (1)
0 Likes
1 Reply
Highlighted
Absent Member.
Absent Member.

An alternate way to do this -

Set xmldom = CreateObject("MSXML2.DOMDocument")
xmldom.Load("xmlfilepath")

'Location at which you need to cop the xml tags
Set targetnode= xmldom.selectSingleNode("/Document/MndtInitnReq/Mndt")

'Rootnode - parent
Set Rootnode = xmldom.selectSingleNode("/Document/MndtInitnReq")
Rootnode .insertBefore new_MndtId , targetnode

Try and see if this works


Accept as solution/Give Kudos to the author if the piece of information answered/helped you to solve your problem.
All the thoughts here are mine not related to my employer nor anyone.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.