How to extract classes from SOAP XML via PHP?

249

Im new to SOAP UI, so is there any method to extract key->value pairs from SOAP UI. I.e. reading "index" of what SOAP interface has to offer? Like reading MIB from SNMP?

For example I can request:

<SOAP:Body>
    <find xmlns="xmlapi">
            <fullClassName>Persons</fullClassName>
            <resultFilter class="Persons.Data">
            <attribute>Name</attribute>
            </resultFilter>
    </find>
 </SOAP:Body>

Class name "Persons" is what I know, but is there a way to retrieve list of "classes" SOAP UI has to offer?

189

Answer

Solution:

If you want to get all<fullClassName> elements inside<find> for a specific request, a possible way is for example using inside a groovy testStep:

// get your response 
def response = context.expand( '${TestRequest#Response}' )
// parse it
def xml = new XmlSlurper().parseText(response)
// find all `<fullClassName>` in your xml
def classNames = xml.'**'.findAll { it.name() == 'fullClassName' }
// print all values
classNames.each{
    log.info "fullClassName: $it"
}

As you are new to SOAPUI (maybe also to Groovy) here are some hints:

context.expand( '${TestRequestName#Property}' ) get the content of the specific property from some scoped element. In your case you've to specify your request name and as a property the Response. For more info see

Groovy automatically useit as a variable for the closures. This is why I useit ineach and infindAll.

UPDATE

If you want to know all possible values supported by<fullClassName> you've the follow options:

  1. Check if the type for<fullClassName> defined in the schema has a<xs:restiction> with<xs:enumeration> with the possible values.
  2. If in the schema the type it's simply an<xs:string> or other type which doesn't give you any clue about the allowed value, contact the provider to see an alternative like if there is another SOAP service which returns the values...

For the first case if you've the.xsd try adding a groovy testStep to parse the.xsd and get the<xs:enumeration> values, see the follow example:

def xsd = '''<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<simpleType name="fullClassNameType">
    <restriction base="string">
        <enumeration value="Persons"/>
        <enumeration value="AnotherClassName"/>
        <enumeration value="AnotherOne"/>
    </restriction>
</simpleType>
</schema>'''

// parse the xsd 
def xml = new XmlSlurper().parseText( xsd )
// find your type by name attribute
def fullClassNameType = xml.depthFirst().find { [email protected] == 'fullClassNameType' }
// get an array with value attribute of enumeration elements
def allowedValues = fullClassNameType.restriction.enumeration*[email protected]
log.info allowedValues // [Persons, AnotherClassName, AnotherOne]

Hope it helps,

People are also looking for solutions to the problem: php - PDO Query not inserting in Database

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.