Forum Discussion

pkunst's avatar
pkunst
Contributor
11 years ago

Problem with reading value of xml node

Hi there,
I have another xml problem. I am trying to read the value of a child node, but I am failing.
At first I try to get the parent node by index.

Then I want the children. At this point my script fails.
def parentNode = holder.getDomNodes("//*:BatchLogDTO")[1]
def childNode = node.children()[2]


This message occurs:
groovy.lang.MissingMethodException: No signature of method: org.apache.xmlbeans.impl.store.Xobj$ElementXobj.children() is applicable for argument types: () values: [] error at line: 10



Also I tried this:
def node = holder.getDomNodes("//flex.messaging.io.amf.ASObject[1]/BatchLogDTO/*")
def cNode = node.children()[2]

But then this message occurs:
groovy.lang.MissingMethodException: No signature of method: [Lorg.w3c.dom.Node;.children() is applicable for argument types: () values: [] error at line: 14


So this is what I want to do:
1. Get the parent node by name and index (there are multiple of it)
2. Get a child node by name i.e. “ChildNode5”
3. Read the value of the child node

3 Replies

  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    Try this:

    Java Doc for Nodes

    I don't use XmlHolder too much since it requires the context to be called and the majority of my coding is actually external to SoapUI right now but that might help you. Worst case, you may need to import:

    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
  • Thank you. Now it works.
    But there is another problem:
    java.lang.RuntimeException: DOM Level 3 not implemented

    This message I get by using the method getTextContent().

    Is there a way to implement DOM Level 3 or do I have to find a work around?
  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    I forgot about all the issues I had ran into with the transition from XmlHolder to DOM. I rarely deal with returned values with SoapUI lately since the majority of my projects has been based on building the requests, not dealing with responses, for the last couple weeks.


    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    def XmlUtils = com.eviware.soapui.support.xml.XmlUtils;

    for ( tests in testRunner.testCase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep.class) ) {
    def xml = XmlUtils.parseXml(tests.getPropertyValue("Request"));
    def children = xml.getChildNodes();
    def childNode = children.getChildNodes().item(0);
    log.info childNode.getNodeName();
    }


    This is a rather brutal way to go about it but it should lead you in the right direction hopefully. I extremely rarely deal with GroovyUtils since it requires context and my program bounces around a lot. I hope this helps, XmlUtils will likely be more along the lines of what you are wanting to use.