Forum Discussion

SunkaraSuresh05's avatar
SunkaraSuresh05
New Contributor
5 years ago
Solved

How to create childNodes within childnode in sopaui (Using Groovy)

Hi, I am trying to create a child nodes within a child node dynamically using groovy script as below:   <ns26:Entry> ns26:ContactType>ABPerson</ns26:ContactType> <ns26:FirstName>Axafoname</ns26:Fi...
  • SunkaraSuresh05's avatar
    5 years ago

    Hello,

     

    Found the answer. I had to use the all children nodes 'appendChild' to main child node as follows:

    allRowsDataForCreatedParnters.find { String line ->  
    	
    	  if(line.contains(Ibnnumber))
    	  {
    	  	jsonObjectForPartner = jsonSlurper.parseText(line)
    	  	parentnode = holderIban.getDomNode("//*:Results")
    	  	xmldoc = parentnode.ownerDocument 
    		childentry = parentnode.appendChild(xmldoc.createElementNS(parentnode.getNamespaceURI(),"Entry"))
    		child = parentnode.appendChild(xmldoc.createElementNS(parentnode.getNamespaceURI(),"ContactType"))
    		child2 = parentnode.appendChild(xmldoc.createElementNS(parentnode.getNamespaceURI(),"DateOfBirth"))
    		child3 = parentnode.appendChild(xmldoc.createElementNS(parentnode.getNamespaceURI(),"FirstName"))
    		child4 = parentnode.appendChild(xmldoc.createElementNS(parentnode.getNamespaceURI(),"LastName"))
    		child5 = parentnode.appendChild(xmldoc.createElementNS(parentnode.getNamespaceURI(),"LinkID"))
    		child6 = parentnode.appendChild(xmldoc.createElementNS(parentnode.getNamespaceURI(),"Prefix"))
    		child7 = parentnode.appendChild(xmldoc.createElementNS(parentnode.getNamespaceURI(),"AddressLine1"))
    		child8 = parentnode.appendChild(xmldoc.createElementNS(parentnode.getNamespaceURI(),"City"))
    		child9 = parentnode.appendChild(xmldoc.createElementNS(parentnode.getNamespaceURI(),"Postal"))
    		child10 = parentnode.appendChild(xmldoc.createElementNS(parentnode.getNamespaceURI(),"Gender_De"))
    	
    		child.appendChild(xmldoc.createTextNode(jsonObjectForPartner.ContactType))
    		childentry.appendChild(child)
    		child2.appendChild(xmldoc.createTextNode(jsonObjectForPartner.DateOfBirth))
    		childentry.appendChild(child2)
    		child3.appendChild(xmldoc.createTextNode(jsonObjectForPartner.FirstName))
    		childentry.appendChild(child3)
    		child4.appendChild(xmldoc.createTextNode(jsonObjectForPartner.LastName))
    		childentry.appendChild(child4)
    		child5.appendChild(xmldoc.createTextNode(jsonObjectForPartner.LinkID))
    		childentry.appendChild(child5)
    		child6.appendChild(xmldoc.createTextNode(jsonObjectForPartner.Prefix))
    		childentry.appendChild(child6)
    		child7.appendChild(xmldoc.createTextNode(jsonObjectForPartner.AddressLine1))
    		childentry.appendChild(child7)
    		child8.appendChild(xmldoc.createTextNode(jsonObjectForPartner.City))
    		childentry.appendChild(child8)
    		child9.appendChild(xmldoc.createTextNode(jsonObjectForPartner.PostalCode))
    		childentry.appendChild(child9)
    		child10.appendChild(xmldoc.createTextNode(jsonObjectForPartner.Gender))
    		childentry.appendChild(child10)

    Thank you so much nmrao for your quick responses.