Ask a Question

Count the number of tags

radhika1
Contributor

Count the number of tags

<ns0:esbEnvelope xmlns:ns0="http://moneygram.com/esb_v3">
<ns0:header>
<ns0:messageGUID>00000164bdc7c9a7-1d58dec</ns0:messageGUID>
<ns0:sessionGUID/>
<ns0:routingContext>
<ns1:serviceFunctionID xmlns:ns1="http://moneygram.com/core/common_v3">GetUCP1705</ns1:serviceFunctionID>
<ns1:esbClientSystemId xmlns:ns1="http://moneygram.com/core/common_v3">GetUCPTransactionHistoryOrchestrator</ns1:esbClientSystemId>
<ns1:mgiAPIID xmlns:ns1="http://moneygram.com/core/common_v3">1705</ns1:mgiAPIID>
<ns1:poeTypeID xmlns:ns1="http://moneygram.com/core/common_v3">AGENTCONNECT</ns1:poeTypeID>
<ns1:agentLocationID xmlns:ns1="http://moneygram.com/core/common_v3"/>
<ns1:configurationExceptionToken xmlns:ns1="http://moneygram.com/core/common_v3"/>
<ns1:esbEnvelopeVersion xmlns:ns1="http://moneygram.com/core/common_v3">v3</ns1:esbEnvelopeVersion>
</ns0:routingContext>
<ns0:processingInstruction>
<ns1:action xmlns:ns1="http://moneygram.com/core/common_v3">MDM_GetUCP_SYNC_HTTP_1705</ns1:action>
<ns1:language xmlns:ns1="http://moneygram.com/core/common_v3">en-US</ns1:language>
<ns1:rollbackTransaction xmlns:ns1="http://moneygram.com/core/common_v3">true</ns1:rollbackTransaction>
<ns1:logLevelCode xmlns:ns1="http://moneygram.com/core/common_v3">2</ns1:logLevelCode>
<ns1:serviceTimeoutMillisecs xmlns:ns1="http://moneygram.com/core/common_v3">15000</ns1:serviceTimeoutMillisecs>
<ns1:customFields xmlns:ns1="http://moneygram.com/core/common_v3">
<ns1:NameValue>
<ns1:Name>targetAudience</ns1:Name>
<ns1:Value>AGENT_FACING</ns1:Value>
</ns1:NameValue>
<ns1:NameValue>
<ns1:Name>langaugeISOCode</ns1:Name>
<ns1:Value>eng</ns1:Value>
</ns1:NameValue>
<ns1:NameValue>
<ns1:Name>langaugeCode</ns1:Name>
<ns1:Value>en</ns1:Value>
</ns1:NameValue>
<ns1:NameValue>
<ns1:Name>MediatorUseTypeCode</ns1:Name>
<ns1:Value>RQST</ns1:Value>
</ns1:NameValue>
<ns1:NameValue>
<ns1:Name>isNewMgiReceiveTransactionSessionIDFlag</ns1:Name>
<ns1:Value>true</ns1:Value>
</ns1:NameValue>
</ns1:customFields>
</ns0:processingInstruction>
<ns0:ExternalClientHeader xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns1:clientRequestID xmlns:ns1="http://moneygram.com/core/common_v3">00000164bdc7c9a7-1d58dec</ns1:clientRequestID>
<ns1:clientSoftwareVersion xmlns:ns1="http://moneygram.com/core/common_v3">1705</ns1:clientSoftwareVersion>
<ns1:timestamp xmlns:ns1="http://moneygram.com/core/common_v3">2018-09-17T16:08:01.122</ns1:timestamp>
</ns0:ExternalClientHeader>
</ns0:header>
<ns0:responsePayload>
<ns1:orchestrateGetUCPResponse xmlns:ns1="http://moneygram.com/core/service/OrchestrateGetUCP1705">
<consumerProfile>
<cityOfBirth>GBRDDDD</cityOfBirth>
<countryOfBirthCountryCode>GBR</countryOfBirthCountryCode>
<dateOfBirth>1990-09-09</dateOfBirth>
<gender>FEMALE</gender>
<preferredLanguage>en-US</preferredLanguage>
<primaryCitizenshipCountryCode>GBR</primaryCitizenshipCountryCode>
<emailAddress>
<emailAddress>RKUMARDD@MONEYGRAM.COM</emailAddress>
<startDate>2018-10-19T21:10:52-05:00</startDate>
<stronglyAuthenticated>false</stronglyAuthenticated>
<type>EMAIL</type>
<notificationPreference>
<method>E-MAIL</method>
<optIn>false</optIn>
<preferredLanguage>en-US</preferredLanguage>
<startDate>2018-10-19T21:10:52-05:00</startDate>
<stronglyAuthenticated>false</stronglyAuthenticated>
<type>TXNN</type>
</notificationPreference>
<notificationPreference>
<method>E-MAIL</method>
<optIn>false</optIn>
<preferredLanguage>en-US</preferredLanguage>
<startDate>2018-10-19T21:10:52-05:00</startDate>
<stronglyAuthenticated>false</stronglyAuthenticated>
<type>MKTN</type>
</notificationPreference>
</emailAddress>

 

For the above response i need to get the count of email address .I wrote the below and i am getting 2 instead of 1.Please assist.

 

import com.eviware.soapui.support.XmlHolder;
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
def response = groovyUtils.getXmlHolder("Operation#Response");
response.namespaces["ns1"] = "http://moneygram.com/core/service/OrchestrateGetUCP1705";
testRunner.testCase.getTestStepByName('Operation').run(testRunner,context)

 

def ReqFile ="C:/Program Files/Java/any.xml"
def g = context.expand('${Operation#Response#//*//consumerProfile//phoneNumber}');

def i1 = response["count(//consumerProfile//phoneNumber)"];
log.info i1
def i = new File(ReqFile )
i.write(g, "UTF-8")

 

 

5 REPLIES 5
JHunt
Community Hero

Try

 

//consumerProfile/emailAddress

instead of

//consumerProfile//emailAddress

When you use the double slash, it finds the consumerProfile/emailAddress and the consumerProfile/emailAddress/emailAddress.

 

Thanks it worked but I need one more help.

 

I need to get the entire xml from the <phone number> tag to </phone number> as there are two occurences for them.

 

i used the below script.

def response = groovyUtils.getXmlHolder("Operation#Response");
response.namespaces["ns1"] = "http://moneygram.com/core/service/OrchestrateGetUCP1705";

for (int y=0;y<count;y++)
{
def i2 = response["//*/consumerProfile/phoneNumber["+y+"]"];

log.info i2;

}

 

i used the below as well and didnt work.

def g  = context.expand('${Operation#Response#//*//consumerProfile/phoneNumber["+y+"]}');

 

XML:

 

 

<phoneNumber>
<countryDialInNumber>1</countryDialInNumber>
<mobileFlag>true</mobileFlag>
<phoneNumber>5128797895</phoneNumber>
<startDate>2018-10-19T21:10:52-05:00</startDate>
<stronglyAuthenticated>false</stronglyAuthenticated>
<type>PRM</type>
<notificationPreference>
<method>SMS</method>
<optIn>false</optIn>
<preferredLanguage>en-US</preferredLanguage>
<startDate>2018-10-19T21:10:52-05:00</startDate>
<stronglyAuthenticated>false</stronglyAuthenticated>
<type>TXNN</type>
</notificationPreference>
<notificationPreference>
<method>SMS</method>
<optIn>true</optIn>
<preferredLanguage>en-US</preferredLanguage>
<startDate>2018-10-19T21:10:52-05:00</startDate>
<stronglyAuthenticated>false</stronglyAuthenticated>
<type>MKTN</type>
</notificationPreference>
</phoneNumber>
<phoneNumber>
<countryDialInNumber>1</countryDialInNumber>
<mobileFlag>true</mobileFlag>
<phoneNumber>6124045907</phoneNumber>
<startDate>2018-10-19T21:10:52-05:00</startDate>
<stronglyAuthenticated>false</stronglyAuthenticated>
<type>SEC</type>
<notificationPreference>
<method>SMS</method>
<optIn>false</optIn>
<preferredLanguage>en-US</preferredLanguage>
<startDate>2018-10-19T21:10:52-05:00</startDate>
<stronglyAuthenticated>false</stronglyAuthenticated>
<type>MKTN</type>
</notificationPreference>
<notificationPreference>
<method>SMS</method>
<optIn>false</optIn>
<preferredLanguage>en-US</preferredLanguage>
<startDate>2018-10-19T21:10:52-05:00</startDate>
<stronglyAuthenticated>false</stronglyAuthenticated>
<type>TXNN</type>
</notificationPreference>
</phoneNumber>

 

 

Do you need the actual XML for the Phone Numbers, or do you just need a way to iterate over them?

 

I don't know how to get the XML, but you can iterate over them like this:

 

def xml = '''<xml>
    <phoneNumber>
        <countryDialInNumber>1</countryDialInNumber>
        <mobileFlag>true</mobileFlag>
        <phoneNumber>5128797895</phoneNumber>
        <startDate>2018-10-19T21:10:52-05:00</startDate>
        <stronglyAuthenticated>false</stronglyAuthenticated>
        <type>PRM</type>
        <notificationPreference>
            <method>SMS</method>
            <optIn>false</optIn>
            <preferredLanguage>en-US</preferredLanguage>
            <startDate>2018-10-19T21:10:52-05:00</startDate>
            <stronglyAuthenticated>false</stronglyAuthenticated>
            <type>TXNN</type>
        </notificationPreference>
        <notificationPreference>
            <method>SMS</method>
            <optIn>true</optIn>
            <preferredLanguage>en-US</preferredLanguage>
            <startDate>2018-10-19T21:10:52-05:00</startDate>
            <stronglyAuthenticated>false</stronglyAuthenticated>
            <type>MKTN</type>
        </notificationPreference>
    </phoneNumber>
    <phoneNumber>
        <countryDialInNumber>1</countryDialInNumber>
        <mobileFlag>true</mobileFlag>
        <phoneNumber>6124045907</phoneNumber>
        <startDate>2018-10-19T21:10:52-05:00</startDate>
        <stronglyAuthenticated>false</stronglyAuthenticated>
        <type>SEC</type>
        <notificationPreference>
            <method>SMS</method>
            <optIn>false</optIn>
            <preferredLanguage>en-US</preferredLanguage>
            <startDate>2018-10-19T21:10:52-05:00</startDate>
            <stronglyAuthenticated>false</stronglyAuthenticated>
            <type>MKTN</type>
        </notificationPreference>
        <notificationPreference>
            <method>SMS</method>
            <optIn>false</optIn>
            <preferredLanguage>en-US</preferredLanguage>
            <startDate>2018-10-19T21:10:52-05:00</startDate>
            <stronglyAuthenticated>false</stronglyAuthenticated>
            <type>TXNN</type>
        </notificationPreference>
    </phoneNumber>
</xml>
'''

new XmlSlurper().parseText(xml)
.'phoneNumber'
.each { 
	log.info "Phone number: ${it.phoneNumber}"
	log.info "Type: ${it.type}"
}

I don't know how to do it with XmlHolder, so this uses XmlSlurper instead.

Hi,

 

Actually my intention is to read the respone from <phonenumber> to </phone number> for the two occurences and write to a text file instead of using it as a string and storing like how u did .Please assit 

Given that your response looks something like this:

 

 

...
    <phoneNumber>
        <countryDialInNumber>1</countryDialInNumber>
        <mobileFlag>true</mobileFlag>
        <phoneNumber>5128797895</phoneNumber>
        <startDate>2018-10-19T21:10:52-05:00</startDate>
        <stronglyAuthenticated>false</stronglyAuthenticated>
    ...
...

 

and that you want the value for the phone number, in the above example 5128797895, than you can use a variation of jhunter's solution, here you go:

 

 

def xml = '''<xml>
    <phoneNumber>
        <countryDialInNumber>1</countryDialInNumber>
        <mobileFlag>true</mobileFlag>
        <phoneNumber>5128797895</phoneNumber>
        <startDate>2018-10-19T21:10:52-05:00</startDate>
        <stronglyAuthenticated>false</stronglyAuthenticated>
        <type>PRM</type>
        <notificationPreference>
            <method>SMS</method>
            <optIn>false</optIn>
            <preferredLanguage>en-US</preferredLanguage>
            <startDate>2018-10-19T21:10:52-05:00</startDate>
            <stronglyAuthenticated>false</stronglyAuthenticated>
            <type>TXNN</type>
        </notificationPreference>
        <notificationPreference>
            <method>SMS</method>
            <optIn>true</optIn>
            <preferredLanguage>en-US</preferredLanguage>
            <startDate>2018-10-19T21:10:52-05:00</startDate>
            <stronglyAuthenticated>false</stronglyAuthenticated>
            <type>MKTN</type>
        </notificationPreference>
    </phoneNumber>
    <phoneNumber>
        <countryDialInNumber>1</countryDialInNumber>
        <mobileFlag>true</mobileFlag>
        <phoneNumber>6124045907</phoneNumber>
        <startDate>2018-10-19T21:10:52-05:00</startDate>
        <stronglyAuthenticated>false</stronglyAuthenticated>
        <type>SEC</type>
        <notificationPreference>
            <method>SMS</method>
            <optIn>false</optIn>
            <preferredLanguage>en-US</preferredLanguage>
            <startDate>2018-10-19T21:10:52-05:00</startDate>
            <stronglyAuthenticated>false</stronglyAuthenticated>
            <type>MKTN</type>
        </notificationPreference>
        <notificationPreference>
            <method>SMS</method>
            <optIn>false</optIn>
            <preferredLanguage>en-US</preferredLanguage>
            <startDate>2018-10-19T21:10:52-05:00</startDate>
            <stronglyAuthenticated>false</stronglyAuthenticated>
            <type>TXNN</type>
        </notificationPreference>
    </phoneNumber>
</xml>
'''


new XmlSlurper().parseText(xml).'**'.findAll {
	it.name() == 'phoneNumber' && !it.childNodes()
}.each {
	log.info it //this will output the phone numbers only!
}

 

The result will look like this:

 

 

Mon Oct 29 18:55:19 CET 2018:INFO:5128797895
Mon Oct 29 18:55:19 CET 2018:INFO:6124045907

 

 

To write the results into a file, edit the below code to your desired destination and format:

 

 

def file = new File("<your filepath and filename here, e.g. c:/output.txt>")

new XmlSlurper().parseText(xml).'**'.findAll {
	it.name() == 'phoneNumber' && !it.childNodes()
}.each {
	log.info it //this will output the phone numbers only!
        file << it // see also here: http://mrhaki.blogspot.com/2009/08/groovy-goodness-working-with-files.html
}

 

cancel
Showing results for 
Search instead for 
Did you mean: