douguadao3883
2017-05-03 04:52
浏览 198

php使用getElementsByTagNameNS从soap读取xml内容

This is my XML which i have:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope 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">
 <soapenv:Body>
  <notifications xmlns="http://soap.sforce.com/2005/09/outbound">
   <OrganizationId>00Dp00000008kXDEAY</OrganizationId>
   <ActionId>04k28000000L3shAAC</ActionId>
   <SessionId xsi:nil="true"/>
   <EnterpriseUrl>https://232.salesforce.com/services/Soap/c/36.0/00Dp00000008kXD</EnterpriseUrl>
   <PartnerUrl>https://232.salesforce.com/services/Soap/u/36.0/00Dp00000008kXD</PartnerUrl>
   <Notification>
    <Id>034l3004D4247lVAAS</Id>
    <sObject xsi:type="sf:SMS_Activity__c" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
     <sf:Id>a0Ip0000001WxvaEAC</sf:Id>
     <sf:Brand__c>ABC</sf:Brand__c>
     <sf:Content__c>halo test</sf:Content__c>
     <sf:Mobile__c>628145783535</sf:Mobile__c>
    </sObject>
   </Notification>
  </notifications>
 </soapenv:Body>
</soapenv:Envelope>

Please help me how to read the value of (brand,content__C,mobile__c) with php code ?

I could not get Mobile__c that from what i tried the below code

 $notif=simplexml_load_string($xml);
      $Mobile=$notif->sObject-
      >children('urn:sobject.enterprise.soap.sforce.com')-
      >Mobile__c.PHP_EOL;
      $qd="";
      $qd="insert into incoming(phone) values('$Mobile')";
      mysql_query($qd);

图片转代码服务由CSDN问答提供 功能建议

这是我的XML:

 &lt;  ?xml version =“1.0”encoding =“UTF-8”?&gt; 
&lt; soapenv:Envelope 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“&gt; 
&lt; soapenv:Body&gt; 
&lt; notifications xmlns =  “http://soap.sforce.com/2005/09/outbound">
&lt; OrganizationId&gt; 00Dp00000008kXDEAY&lt; / OrganizationId&gt; 
&lt; ActionId&gt; 04k28000000L3shAAC&lt; / ActionId&gt; 
&lt; SessionId xsi:nil =  “true”/&gt; 
&lt; EnterpriseUrl&gt; https://232.salesforce.com/services/Soap/c/36.0/00Dp00000008kXD< / EnterpriseUrl&gt; 
&lt; PartnerUrl&gt; https://232.salesforce.com  /services/Soap/u/36.0/00D00000008kXD</PartnerUrl>
&lt; Notification&gt; 
&lt; Id&gt; 034l3004D4247lVAAS&lt; / Id&gt; 
&lt; sObject xsi:type =“sf:SMS_Activity__c”xmlns:sf =“  urn:sobject.enterprise.soap.sforce.com“&gt; 
&lt; sf:Id&gt; a0Ip0000001  WxvaEAC&lt; / sf:Id&gt; 
&lt; sf:Brand _c&gt; ABC&lt; / sf:Brand _c&gt; 
&lt; sf:Content _c&gt; halo test&lt; / sf:Content _c&gt; 
&lt; sf:Mobile__c&gt; 628145783535&lt; / sf  :Mobile _c&gt; 
&lt; / sObject&gt; 
&lt; / Notification&gt; 
&lt; / notifications&gt; 
&lt; / soapenv:Body&gt; 
&lt; / soapenv:Envelope&gt; 
   
 
 

请帮助我如何阅读(品牌,content__C,mobile__c) 的值与PHP代码?

我无法从我试过的那样得到Mobile__c 下面的代码

  $ notif = simplexml_load_string($ xml); 
 $ Mobile = $ notif-&gt; sObject- 
&gt; children('urn:sobject.enterprise  .soap.sforce.com') -  
&gt; Mobile__c.PHP_EOL; 
 $ qd =“”; 
 $ qd =“插入传入(电话)值('$ Mobile')”; 
 mysql_query(  $ qd); 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • dougan4884 2017-05-03 05:18
    最佳回答

    Try this hope this will help you out..

    Try this code snippet here

    <?php
    
    ini_set('display_errors', 1);
    $string='<?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope 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">
     <soapenv:Body>
      <notifications xmlns="http://soap.sforce.com/2005/09/outbound">
       <OrganizationId>00Dp00000008kXDEAY</OrganizationId>
       <ActionId>04k28000000L3shAAC</ActionId>
       <SessionId xsi:nil="true"/>
       <EnterpriseUrl>https://232.salesforce.com/services/Soap/c/36.0/00Dp00000008kXD</EnterpriseUrl>
       <PartnerUrl>https://232.salesforce.com/services/Soap/u/36.0/00Dp00000008kXD</PartnerUrl>
       <Notification>
        <Id>034l3004D4247lVAAS</Id>
        <sObject xsi:type="sf:SMS_Activity__c" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
         <sf:Id>a0Ip0000001WxvaEAC</sf:Id>
         <sf:Brand__c>ABC</sf:Brand__c>
         <sf:Content__c>halo test 1</sf:Content__c>
         <sf:Mobile__c>6281457835351</sf:Mobile__c>
        </sObject>
       </Notification> <Notification>
        <Id>034l3004D4247lVAAS</Id>
        <sObject xsi:type="sf:SMS_Activity__c" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
         <sf:Id>a0Ip0000001WxvaEAC</sf:Id>
         <sf:Brand__c>ABC2</sf:Brand__c>
         <sf:Content__c>halo test 2</sf:Content__c>
         <sf:Mobile__c>6281457835352</sf:Mobile__c>
        </sObject>
       </Notification> <Notification>
        <Id>034l3004D4247lVAAS</Id>
        <sObject xsi:type="sf:SMS_Activity__c" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
         <sf:Id>a0Ip0000001WxvaEAC</sf:Id>
         <sf:Brand__c>ABC3</sf:Brand__c>
         <sf:Content__c>halo test 3</sf:Content__c>
         <sf:Mobile__c>6281457835353</sf:Mobile__c>
        </sObject>
       </Notification>
      </notifications>
     </soapenv:Body>
    </soapenv:Envelope>';
    
    $requiredData=array();
    $result= new DOMDocument();
    $result->loadXML($string);
    foreach(array(
        "Brand__c",
        "Content__c",
        "Mobile__c"
    ) as $key)
    {
        foreach($result->getElementsByTagNameNS("urn:sobject.enterprise.soap.sforce.com",$key) as $element)
        {
            if($element instanceof DOMElement)
            {   
               $requiredData[$element->tagName][] =$element->textContent;
            }
        }
    }
    print_r($requiredData);
    
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题