Micro Focus Contributor
Micro Focus Contributor

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

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

root.insertBefore new_MndtId, root.childNodes.item(1)

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

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

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)
1 Reply
Absent Member.
Absent Member.

An alternate way to do this -

Set xmldom = CreateObject("MSXML2.DOMDocument")

'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.
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.