Forum Discussion

jays's avatar
jays
Occasional Contributor
9 years ago

How to add XML node dynamically with a namespace

I have an optional xml node which I need to add as I am doing data driven testing. I want to add it based on the input and it has a namespace as well. I was able to add the node dynamically, but name...
  • jays's avatar
    9 years ago

    Found the answer. I had to use the 'appendChild' instead of 'addChildElement'.

     

    def parentnode = holder.getDomNode("//v1:GetNames")
    def xmldoc = parentnode.ownerDocument
    def ns = "your namespace address goes here"

    def child = parentnode.appendChild(xmldoc.createElementNS(ns, "Name"))
    child.appendChild(xmldoc.createTextNode("abc"))