2010-03-28 2 views
2
<wsdl:definitions 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"/> 

열거 형의 모든 요소를 ​​얻으려고하고 있지만 올바르게 만들 수없는 것 같습니다. 이것은 숙제이므로 가능한 경우 완전한 해결책을 제시하지 말고 단지 지침 만 따르십시오.이 XML 요소에 액세스 중

$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; 
} 

내가 뭘 잘못하고 있니?

감사

+0

그냥 코멘트, 당신이 두 개의 서로 다른 변수를 가지고 당신의 '$ ns s'와'$ ns_s' 코드를 게시했습니다. –

+0

미안하지만, 오타입니다. 그렇지만 여전히 동일한 문제입니다. – csU

답변

3

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()); 

또 다른 방법은 DOM 확장 사용하는 것입니다 :

$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

내 방식대로 할 수있는 힌트가 있습니다. 게시하는 작업 코드는 내가 겪고있는 일이 무엇인지 알기에 가치가있다. 학생이라는 것은 경험이 부족한 다른 방법을 알지 못한다는 것을 의미한다. 분명히 위의 코드를 사용하면 속임수로 분류 될 것이다. D – csU

+0

@csU 잘, 첫 번째 것은 올바른 네임 스페이스를 사용하는 것입니다. s : enumaration 요소는 XMLSchema 네임 스페이스 안에 있습니다. 그래서 Feed Children을 반복 할 때, 당신은 그것들에 제한하기를 원합니다. – Gordon

+0

클래스 기반 언어에서 사용되는 객체 지향 범위 (C++, PHP, Java 등)와 호환되지 않는 람다 상속 모델을 사용하므로 XML은 네임 스페이스에서 더 우수합니다. –

관련 문제