2012-11-28 34 views
0

我在使用DOMDocument PHP查找WSDL(XML)文檔上的某個節點時遇到問題。當我使用getElementsByTagName時,它總是返回NULL。我要找到的是xsd:complexType,但是當我嘗試不同的節點時,讓我們說類型,它返回一個對象。在DOM上使用PHP查找(XML)節點

這是我的WSDL(XML)文檔

<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:routeDx2" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:routeDx2"> 
<types> 
<xsd:schema targetNamespace="urn:routeDx2" 
> 
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" /> 
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" /> 
<xsd:complexType name="inputCashin"> 
    <xsd:all> 
    <xsd:element name="userName" type="xsd:string"/> 
    <xsd:element name="signature" type="xsd:string"/> 
    <xsd:element name="productCode" type="xsd:string"/> 
    <xsd:element name="merchantCode" type="xsd:string"/> 
    <xsd:element name="terminal" type="xsd:string"/> 
    <xsd:element name="merchantNumber" type="xsd:string"/> 
    <xsd:element name="transactionType" type="xsd:string"/> 
    <xsd:element name="recipientNumber" type="xsd:string"/> 
    <xsd:element name="recipientName" type="xsd:string"/> 
    <xsd:element name="amount" type="xsd:string"/> 
    <xsd:element name="feeAmount" type="xsd:string"/> 
    <xsd:element name="traxId" type="xsd:string"/> 
    <xsd:element name="timeStamp" type="xsd:string"/> 
    </xsd:all> 
</xsd:complexType> 
<xsd:complexType name="inputCashout"> 
    <xsd:all> 
    <xsd:element name="userName" type="xsd:string"/> 
    <xsd:element name="signature" type="xsd:string"/> 
    <xsd:element name="productCode" type="xsd:string"/> 
    <xsd:element name="merchantCode" type="xsd:string"/> 
    <xsd:element name="terminal" type="xsd:string"/> 
    <xsd:element name="merchantNumber" type="xsd:string"/> 
    <xsd:element name="transactionType" type="xsd:string"/> 
    <xsd:element name="recipientNumber" type="xsd:string"/> 
    <xsd:element name="recipientName" type="xsd:string"/> 
    <xsd:element name="amount" type="xsd:string"/> 
    <xsd:element name="feeAmount" type="xsd:string"/> 
    <xsd:element name="verifyingCode" type="xsd:string"/> 
    <xsd:element name="traxId" type="xsd:string"/> 
    <xsd:element name="timeStamp" type="xsd:string"/> 
    </xsd:all> 
</xsd:complexType> 
</xsd:schema> 
</types> 
<definitions> 

什麼,我要找到的是XSD:複雜類型,或者如果可能的話,如何由具有獨特的價值屬性名稱查找(verifyingCode或其他人) ,我該如何通過PHP和DOMDocument完成這項工作?

回答

0

除了您錯誤的結束標記<definitions>(最後一行),我沒有看到問題。

$doc = new DOMDocument(); 
$doc->loadXML($xml); 
$complexTypes = $doc->getElementsByTagName('complexType'); 
printf('<p>Found %d complexType elements</p>', $complexTypes->length); 
foreach ($complexTypes as $complexType) { 
    echo $complexType->getAttribute('name'), '<br>'; 
} 

演示 - http://codepad.viper-7.com/95XDsS

你可能要包括你的標籤名稱查詢xsd命名空間。如果你讀了docs,你會看到參數getElementsByTagName()指定

本地名(不含命名空間)標籤的匹配上

+0

我包括我的查詢XSD命名空間,這是作品。謝謝 :) –