开发者

Accessing elements of this xml

开发者 https://www.devze.com 2022-12-25 02:20 出处:网络
<wsdl:d开发者_如何转开发efinitions targetNamespace=\"http://www.webserviceX.NET/\"> <wsdl:types>
<wsdl:d开发者_如何转开发efinitions targetNamespace="http://www.webserviceX.NET/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://www.webserviceX.NET/">
<s:element name="ConversionRate">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="FromCurrency" type="tns:Currency"/>
<s:element minOccurs="1" maxOccurs="1" name="ToCurrency" type="tns:Currency"/>
</s:sequence>
</s:complexType>
</s:element>
<s:simpleType name="Currency">
<s:restriction base="s:string">
<s:enumeration value="AFA"/>
<s:enumeration value="ALL"/>
<s:enumeration value="DZD"/>
<s:enumeration value="ARS"/>

I am trying to get at all of the elements in enumeration but can't seem to get it right. This is homework so please no full solutions, just guidance if possible.

$feed = simplexml_load_file('http://www.webservicex.net/CurrencyConvertor.asmx?WSDL');

foreach($feed->simpleType as $val){
    $ns s = $val->children('http://www.webserviceX.NET/');
    echo $ns_s -> enumeration;
}

What am I doing wrong?

thanks


The following works with PHP 5.2:

$feedUrl = 'http://www.webservicex.net/CurrencyConvertor.asmx?WSDL';
$feed = simplexml_load_file($feedUrl);
$feed->registerXPathNamespace('s', 'http://www.w3.org/2001/XMLSchema');
foreach( $feed->xpath('//s:enumeration/@value') as $enumNode) {
    echo $enumNode, PHP_EOL;
}

print_r( $feed->getDocNamespaces() );

Another approach would be to use the DOM extension:

$feed = new DomDocument;
$feed->load('http://www.webservicex.net/CurrencyConvertor.asmx?WSDL');
$nodes = $feed->getElementsByTagNameNS(
    'http://www.w3.org/2001/XMLSchema', 
    'enumeration');

foreach( $nodes as $node ) {
    echo $node->getAttribute('value'), PHP_EOL;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号