Forum Discussion

pleuraXeraphim's avatar
pleuraXeraphim
Occasional Contributor
16 years ago

holder.getDomNodes - Accessing the Children of a DomNode ?

Hi
A straight forward question and I think I am nearly there but I cannot find the answer in the forums or in the documentation.
I'm trying to parse some XML (See below/bottom) from the AMF Response:

Basically I'm trying to pull out each of the Nodes and its elements and create an object for each one :
I started with the following which works:

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder("GetUserTypes#ResponseAsXml")

def items = holder.getNodeValues( "//map/descendant::*")

for ( node in items) {

log.info( node );
}

This works fine and prints out all the elements for each of the Nodes.
However it prints out all the elements in one go. I want to be able to examine each Node and its children independent of the other nodes.

So I tried the following instead, I added these two lines:

def xmlUtil = new com.eviware.soapui.support.xml.XmlUtils();
def items = holder.getDomNodes( "//map" );

instead of the following line:

def items = holder.getNodeValues( "//map/descendant::*")

Now when i run it I get the a print out for each of my 7 map nodes as follows for each loop iteration of the loop which looks good:
Nearly there I think:

Fri Apr 16 16:13:12 BST 2010:INFO:org.apache.xmlbeans.impl.store.Xobj$ElementXobj@264816
Fri Apr 16 16:13:12 BST 2010:INFO:org.apache.xmlbeans.impl.store.Xobj$ElementXobj@146a6af
Fri Apr 16 16:13:12 BST 2010:INFO:org.apache.xmlbeans.impl.store.Xobj$ElementXobj@1695b00
Fri Apr 16 16:13:12 BST 2010:INFO:org.apache.xmlbeans.impl.store.Xobj$ElementXobj@1d582a7
Fri Apr 16 16:13:12 BST 2010:INFO:org.apache.xmlbeans.impl.store.Xobj$ElementXobj@74b452
Fri Apr 16 16:13:12 BST 2010:INFO:org.apache.xmlbeans.impl.store.Xobj$ElementXobj@1ea7f02
Fri Apr 16 16:13:12 BST 2010:INFO:org.apache.xmlbeans.impl.store.Xobj$ElementXobj@388130

Great but how can I access the values of the Nodes childrens  ?

Any help appreciated.

Here is a snippet of the XML I am parsing:

 
     
     
       
          0.75
          12
       

        16
        4
        typeName
        Daves User Type
        id
        500.0
        isDefault
        false
        description
        Super Dooper User Type
     

     
       
          false
          false
          com.mdsuk.esuite.common.model.UserType
       

     

   

   
     
     
       
          0.75
          12
       

        16
        4
        typeName
        Aspect 1
        id
        510.0
        isDefault
        false
        description
        Aspect 1
     

3 Replies

  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Is this any help?

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder("GetUserTypes#ResponseAsXml")

    def nodeCount = holder.getDomNodes("//flex.messaging.io.amf.ASObject/map").length
    log.info nodeCount

    for (def nodeIndex = 1; nodeIndex <= nodeCount; nodeIndex++) {
    def node = holder.getDomNodes("//flex.messaging.io.amf.ASObject["+nodeIndex+"]/map/*")
    node.each {
    log.info "map node " + nodeIndex + " - " + it.QName.toString() + ":" + it.firstChild.nodeValue
    }
    }
  • resmis19's avatar
    resmis19
    Occasional Contributor
    I have a query here.

    I'm trying to read from an external xml file.

    -<Currencies>
    <Currency1>AUD</Currency1>
    <Currency2>AWG</Currency2>
    </Currencies

    I can read the nodes one by one and put it in the properties file.
    String s1= new File("${url}").text
    def holder = groovyUtils.getXmlHolder(s1);

    def C1 = holder.getNodeValue("//Currency1")
    propTestStep = context.testCase.getTestStepByName("Pro")
    propTestStep.setPropertyValue("Currency1", C1)

    def C2 = holder.getNodeValue("//Currency2")
    propTestStep = context.testCase.getTestStepByName("Pro")
    propTestStep.setPropertyValue("Currency2", C2)

    but I instead of this,i want to find the count and then loop using for loop.

    I tried like this: def nodeCount = holder.getNodeValues
    But did not return anything.
    any help is appreciated.