首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP:如何处理SOAP响应以获得标记值?

PHP:如何处理SOAP响应以获得标记值?
EN

Stack Overflow用户
提问于 2010-05-28 09:22:27
回答 2查看 3.3K关注 0票数 0

在var $soap_response中有这样的SOAP响应:

代码语言:javascript
复制
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0">
   <SOAP-ENV:Header>
      <h3:__MethodSignature xsi:type="SOAP-ENC:methodSignature" SOAP-ENC:root="1" xmlns:h3="http://schemas.microsoft.com/clr/soap/messageProperties" xmlns:a2="http://schemas.microsoft.com/clr/ns/System.Collections">xsd:string a2:Hashtable</h3:__MethodSignature>
   </SOAP-ENV:Header>
   <SOAP-ENV:Body>
      <i4:ReturnDataSetResponse id="ref-1" xmlns:i4="http://schemas.microsoft.com/clr/nsassem/TOIServerAppl.clsRSchedule/TOIServerAppl">
         <return href="#ref-6"/>
      </i4:ReturnDataSetResponse>
      <a3:DataSet id="ref-6" xmlns:a3="http://schemas.microsoft.com/clr/nsassem/System.Data/System.Data%2C%20Version%3D1.0.5000.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Db77a5c561934e089">
         <XmlSchema id="ref-7"><![CDATA[<?xml version="1.0" encoding="utf-16"?>
            <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
              <xs:element name="NewDataSet" msdata:IsDataSet="true">
                <xs:complexType>
                  <xs:choice maxOccurs="unbounded">
                    <xs:element name="Table">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="id" type="xs:long" msdata:targetNamespace="" minOccurs="0" />
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:choice>
                </xs:complexType>
              </xs:element>
            </xs:schema>]]>
        </XmlSchema>
        <XmlDiffGram id="ref-8">
            <id>4437031</id>
        </XmlDiffGram>
      </a3:DataSet>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

如何从<id>4437031</id>?中提取id值

代码语言:javascript
复制
simplexml_load_string($soap_response);

返回空对象数组。

我已经看到了一些地方,我可能不得不替换所有这些名称空间,使其工作?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-05-28 16:25:12

我能够用SoapClient和__doRequest()函数来完成它。Zend_Soap_client还使用SoapClient。所以我选择了SoapClient。

票数 1
EN

Stack Overflow用户

发布于 2010-05-28 13:18:48

让我为您节省大量的麻烦,并帮助您处理数据集(我假设这是您的web服务,如果不是,我很抱歉)。

不要序列化整个数据集,而是先运行这个函数,然后以字符串的形式返回它。

代码语言:javascript
复制
Public Function FormatDataSet(ByVal ds As DataSet)
    Try
        Dim xmlstream As New StringBuilder
        Dim write As XmlWriter = XmlWriter.Create(xmlstream)
        write.WriteProcessingInstruction("xml", "version='1.0' encoding='utf-8'")
        ds.WriteXml(write)
        Return xmlstream.ToString()
    Catch ex As Exception
        Return ex.Message
    End Try
End Function

这将去掉.NET的模式,并为您提供轻松解析的XML (即使是SimpleXML也能够解析它)。你需要System.Text和System.Xml

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2927849

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档