Forum Discussion

Paramanand_Ghod's avatar
Paramanand_Ghod
Contributor
16 years ago

how to get Count of a tag using groovy scripting

Hi,

How to get the count of a tag which appears multiple times in the XML using groovy scripting.

See the below example:

<GetApplicationDetailsResponse><ApplicationDetails><Attachments>

<DocumentMetaData>
<ID>38273</ID><Reference>43348</Reference><Status>&lt;![CDATA[]]&gt;</Status>
</DocumentMetaData>

<DocumentMetaData>
<ID>38274</ID><Reference>43349</Reference><Status>&lt;![CDATA[]]&gt;</Status>
</DocumentMetaData>

</Attachments></ApplicationDetails></GetApplicationDetailsResponse>

3 Replies

  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Actually, it would be simpler to do this:

    def testxml = '''<Document>
    <DocumentMetaData>
    <ID>38273</ID><Reference>43348</Reference><Status>&lt;![CDATA[]]&gt;</Status>
    </DocumentMetaData>
    <DocumentMetaData>
    <ID>38274</ID><Reference>43349</Reference><Status>&lt;![CDATA[]]&gt;</Status>
    </DocumentMetaData>
    </Document>'''

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
    def holder = groovyUtils.getXmlHolder( testxml )

    log.info holder.getNodeValues("//DocumentMetaData").size();