Accessing elements of this xml

<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"/>

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

-------------Problems Reply------------

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

Category:php Views:0 Time:2010-03-28

Related post

  • Accessing Elements/Attributes From XML Using SimpleXML/PHP 2012-03-29

    Quick question: I'm using PHP's SimpleXML object to parse an XML file. For the life of me, I can't figure out how to access specific elements. My question is what would my PHP look like to access the nodes and the info contained in the "data" attribu

  • Accessing Elements/Attributes From XML Using DomXML 2012-03-30

    I'm forced to use a server running PHP 4 and the XML service that's on the server is DomXML. My question is how do I access specific elements and attributes of the following XML document using DomXML? I tried the following with no results returned. A

  • Why can't I access elements inside an XML file with XPath in XML::LibXML? 2010-01-17

    I have an XML file, part of which looks like this: <wave waveID="1"> <well wellID="1" wellName="A1"> <oneDataSet> <rawData>0.1123975676</rawData> </oneDataSet> </well> ... more wellID's and rawData continues

  • PHP: How to access the last element in a XML file 2012-04-11

    I have an XML file that I want to be able to access the last element in the file. (NOTE: the file is dynamically updated and the latest values are always in the latest element: <?xml version="1.0"?> <tran> <balance>25000</balance

  • Ignoring a particular element of an xml file under SVN version control 2011-05-03

    The full story is that I'm exporting a table within ms-access 2007 as an xml file (schema and data). The problem I'm having is with the following element: <dataroot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" generated="2011-05-03T12:15:

  • how can i operate the element of the xml use the actionscript 2012-02-07

    <fpdl:StartNode Id="Goods_Deliver_Process.START_NODE" Name="START_NODE" DisplayName=""> <fpdl:ExtendedAttributes> <fpdl:ExtendedAttribute Name="FIRE_FLOW.bounds.height" Value="20"/> <fpdl:ExtendedAttribute Name="FIRE_FLOW.bounds.

  • How to get tag name of root element in an XML document w/ XSLT? 2008-12-15

    I'm interested in assigning the tag name of the root element in an xml document to an xslt variable. For instance, if the document looked like (minus the DTD): <foo xmlns="http://....."> <bar>1</bar> </foo> and I wanted to ass

  • Can I configure the DataContractSerializer to not create optional (i.e. Nullable and List) elements in output XML? 2009-04-01

    I am using the new .NET 3.0 DataContractSerializer. I have both Nullable<> and List<> objects I am going to serialize. Example: [DataContract(Namespace = "")] class Test { public static void Go() { Test test = new Test(); var dcs = new Da

  • Actionscript3: how can I access elements on the stage from external classes? 2009-04-04

    I have an external class in a .as file, my problem is that I can't access elements on the stage. Code like stage.txtfield.text or this.parent.txtfield.text does not work. The txtfield is the instace name of a Dynamic Text field. --------------Solutio

  • access elements of datagrid view 2009-04-13

    string s = dataGridView1[0, 0].ToString(); string s2 = dataGridView1[0, 1].ToString(); I used the above method to access elements of datagridview. but i'm getting only these values in 's' and 's2' "DataGridViewTextBoxCell { ColumnIndex=0, RowIndex=0

  • How do you make an element in an XML Schema that allows any HTML element as its children? 2009-05-31

    I am trying to create an element in an XML schema such that only standard (X)HTML elements can be used as children. What I've tried is this: <xs:element name="description"> <xs:complexType> <xs:sequence minOccurs="0" maxOccurs="unbound

  • Accessing elements with offsets in Python's for .. in loops 2009-08-15

    I've been mucking around a bit with Python, and I've gathered that it's usually better (or 'pythonic') to use for x in SomeArray: rather than the more C-style for i in range(0, len(SomeArray)): I do see the benefits in this, mainly cleaner code, and

  • C - How to access elements of vector using GCC SSE vector extension 2009-11-20

    Usually I work with 3D vectors using following types: typedef vec3_t float[3]; initializing vectors using smth. like: vec3_t x_basis = {1.0, 0.0, 0.0}; vec3_t y_basis = {0.0, 1.0, 0.0}; vec3_t z_basis = {0.0, 0.0, 1.0}; and accessing them using smth.

  • Do I need elements in persistence.xml? 2009-11-22

    I have very simple persistance.xml file: <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.s

  • How to access elements of matrices from mat file in python? 2010-01-09

    When load matrices from mat file in python using scipy.io, it makes dictionary where key is name of matrix,and value is 2D array of that matrix. How can i access elements in this array? --------------Solutions------------- Suppose you have mat = sio.

  • how to access element whose id is variable 2010-02-25

    I need to access elements in html file using javascript, their names are like arr_1, arr_2, arr_3, I wish to use a loop to dynamically create the id then to access them like below: for(var i=0; i< 10; i++) { var id = "arr_" + i; $document.getEleme

  • WPF: How to access Element in ListView.ItemTemplate? 2010-03-04

    I need to access element named "PageHost" for the selected list item in the following XAML code from C# codebehind, how to do so please ? <ListView.Resources> <p:PageWidthConverter x:Key="PageWidthConverter" /> </ListView.Resources>

  • use DOMdocument to append elements in a XML-file? 2010-03-06

    i'm using the DOMdocument class in php whenever i want to create a XML document. but how could i open a XML document and add elements after an existing element in the XML document? its a very huge XML-document so it would be great to consider the mos

  • VB.NET add an element to the XML document with LINQ to XML 2010-03-15

    I'm adding an element to existing XML doc with the following code: Dim theXMLSource As String = Server.MapPath("~/Demo/") & "LabDemo.xml" Dim nodeElement As XElement Dim attrAndValue As XElement = _ <LabService> <ServiceType> <%= t

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.150 (s). 11 q(s)