Forum Discussion

Brandon_Tucker's avatar
Brandon_Tucker
Occasional Contributor
16 years ago

How do I add child nodes with xmlUtils?

I have code currently that grabs the parent node I need. I would like to add child nodes to this parent. I remember a methods in javaScript to do this, but not sure how to do it in the soapui api. I think this is the method that I would need.
public static org.w3c.dom.Element addChildElement(org.w3c.dom.Element element,
                                                  java.lang.String name,
                                                  java.lang.String text)

However, I am not sure how to create the element to give to this method.

2 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    If you have the parent element you can create en Element by using parent.getOwnerDocument().createElement(String elementName).
    This element can then be given to the addChildElement method. To set the contents of the element, see the Element documentation.
    Hope this helps!

    Regards,
    Dain
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    I think I may have misunderstood your question initially.

    Using XmlUtils.addChildElement() you feed it the parent node which you have, the desired element name, and desired text content.

    Regards,
    Dain