2013-08-09 2 views
0

내 XML은 다음과 같습니다객체를 생성하지 simplexml_load_string

<?xml version="1.0" encoding="UTF-8"?> 
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <soap:Body> 
     <FindOrders xmlns="http://www.JOI.com/schemas/ViaSub.WMS/"> 
     <orders> 
      <order> 
       <MarkForName /> 
       <BatchOrderID /> 
       <CreationDate>2013-08-09T17:41:00</CreationDate> 
       <EarliestShipDate /> 
       <ShipCancelDate /> 
       <PickupDate /> 
       <Carrier>USPS</Carrier> 
       <BillingCode>Prepaid</BillingCode> 
       <TotWeight>0.00</TotWeight> 
       <TotCuFt>0.00</TotCuFt> 
       <TotPackages>1.0000</TotPackages> 
       <TotOrdQty>1.0000</TotOrdQty> 
       <TotLines>1.00</TotLines> 
       <Notes /> 
       <OverAllocated /> 
       <PickTicketPrintDate /> 
       <ProcessDate /> 
       <TrackingNumber /> 
       <LoadNumber /> 
       <BillOfLading /> 
       <MasterBillOfLading /> 
       <ASNSentDate /> 
       <ConfirmASNSentDate /> 
       <RememberRowInfo>398879:12:2:::0:False</RememberRowInfo> 
      </order> 
     </orders> 
     </FindOrders> 
     <totalOrders xmlns="http://www.JOI.com/schemas/ViaSub.WMS/">1</totalOrders> 
    </soap:Body> 
</soap:Envelope> 

내가 할 경우 :

$a = simplexml_load_string($str); 

print_r($a); 

내가 얻을 : SimpleXMLElement Object ()을 대신하는 모든 매개 변수와 객체의. 왜 이런거야?

답변

1

당신은 SOAP의 namespace declaration (php manual) 누락

$a = simplexml_load_string($str); 
$a->registerXPathNamespace('soap', 'http://www.w3.org/2003/05/soap-envelope'); 

$result = $a->xpath('//soap:Body'); 

print_r($result); 

결과 (preview)

Array 
(
    [0] => SimpleXMLElement Object 
     (
      [FindOrders] => SimpleXMLElement Object 
       (
        [orders] => SimpleXMLElement Object 
         (
          [order] => SimpleXMLElement Object 
    ... 
    ... 
0

난 당신이있어, 당신은 모든 매개 변수를 사용하여 객체를보고 싶어 말할 때 같은데요 방금 작성한 xml 문서를 출력합니다. http://www.php.net/manual/en/simplexmlelement.asxml.php에서 문서를 보면

, 여기 당신이해야 할 작업은 다음과 같습니다

echo $a->asXML(); 
관련 문제