如何通过 PHP 从 SOAP XML 中提取 类?
How to extract classes from SOAP XML via PHP?
我是 SOAP 的新手 UI,所以有什么方法可以从 SOAP UI 中提取键->值对。 IE。阅读 "index" 必须提供的 SOAP 接口?喜欢从 SNMP 读取 MIB?
例如我可以请求:
<SOAP:Body>
<find xmlns="xmlapi">
<fullClassName>Persons</fullClassName>
<resultFilter class="Persons.Data">
<attribute>Name</attribute>
</resultFilter>
</find>
</SOAP:Body>
Class 名称 "Persons" 是我所知道的,但是有没有办法检索 "classes" SOAP UI 必须提供的列表?
如果您想为特定请求获取 <find>
中的所有 <fullClassName>
元素,一种可能的方法是例如在 [=67 中使用 XmlSlurper =] 测试步骤:
// 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"
}
由于您是 SOAPUI(可能也是 Groovy)的新手,这里有一些提示:
context.expand( '${TestRequestName#Property}' )
从某个作用域元素中获取特定 属性 的内容。在您的情况下,您必须指定您的请求名称并作为 属性 响应。有关详细信息,请参阅 property expansion documentation
Groovy 自动使用 it
作为闭包的变量。这就是为什么我在 each
和 findAll
.
中使用 it
更新
如果您想知道 <fullClassName>
支持的所有可能值,您有以下选项:
- 检查 架构 中定义的
<fullClassName>
的类型是否具有 <xs:restiction>
和 <xs:enumeration>
以及可能的值。
- 如果在 schema 中类型只是一个
<xs:string>
或其他类型,它不会为您提供有关允许值的任何线索,请联系提供商以查看一个替代方案,比如如果有另一个 SOAP 服务 returns 值...
对于第一种情况,如果您有 .xsd
,请尝试添加 groovy testStep 来解析 .xsd
并获取 <xs:enumeration>
值,请参见以下示例:
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 { it.@name == 'fullClassNameType' }
// get an array with value attribute of enumeration elements
def allowedValues = fullClassNameType.restriction.enumeration*.@value
log.info allowedValues // [Persons, AnotherClassName, AnotherOne]
希望对您有所帮助,
我是 SOAP 的新手 UI,所以有什么方法可以从 SOAP UI 中提取键->值对。 IE。阅读 "index" 必须提供的 SOAP 接口?喜欢从 SNMP 读取 MIB?
例如我可以请求:
<SOAP:Body>
<find xmlns="xmlapi">
<fullClassName>Persons</fullClassName>
<resultFilter class="Persons.Data">
<attribute>Name</attribute>
</resultFilter>
</find>
</SOAP:Body>
Class 名称 "Persons" 是我所知道的,但是有没有办法检索 "classes" SOAP UI 必须提供的列表?
如果您想为特定请求获取 <find>
中的所有 <fullClassName>
元素,一种可能的方法是例如在 [=67 中使用 XmlSlurper =] 测试步骤:
// 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"
}
由于您是 SOAPUI(可能也是 Groovy)的新手,这里有一些提示:
context.expand( '${TestRequestName#Property}' )
从某个作用域元素中获取特定 属性 的内容。在您的情况下,您必须指定您的请求名称并作为 属性 响应。有关详细信息,请参阅 property expansion documentation
Groovy 自动使用 it
作为闭包的变量。这就是为什么我在 each
和 findAll
.
it
更新
如果您想知道 <fullClassName>
支持的所有可能值,您有以下选项:
- 检查 架构 中定义的
<fullClassName>
的类型是否具有<xs:restiction>
和<xs:enumeration>
以及可能的值。 - 如果在 schema 中类型只是一个
<xs:string>
或其他类型,它不会为您提供有关允许值的任何线索,请联系提供商以查看一个替代方案,比如如果有另一个 SOAP 服务 returns 值...
对于第一种情况,如果您有 .xsd
,请尝试添加 groovy testStep 来解析 .xsd
并获取 <xs:enumeration>
值,请参见以下示例:
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 { it.@name == 'fullClassNameType' }
// get an array with value attribute of enumeration elements
def allowedValues = fullClassNameType.restriction.enumeration*.@value
log.info allowedValues // [Persons, AnotherClassName, AnotherOne]
希望对您有所帮助,