Jump to content

Parse XML dataset returned from .NET web service


kiwikev

Recommended Posts

Hi

I'm trying to find a answer to the following, have been trying google but I must be missing something basic as I just cant seem to find the answer (my PHP skills are a bit outdated). I have developed a webservice in .NET ASP 2.0 that returns a dataset (example below). I need to be able to provide a PHP code snipit to another developer so they can call it and manipulate the data. I'm using PHP5 and the SoapClient with the service wsdl to call the service... how do I parse the returned dataset with its embedded XML schema into a object that I can simply loop through in PHP?

Thanks in advance...

K


Example of XML returned in result.

<?xml version="1.0" encoding="utf-8" ?>
<DataSet xmlns="http://ttt.co.nz/">
<xs:schema id="getQuoteExample" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="getQuoteExample" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="General">
<xs:complexType>
<xs:sequence>
<xs:element name="Status" type="xs:int" minOccurs="0" />
<xs:element name="StatusDOB" type="xs:int" minOccurs="0" />
<xs:element name="StatusGender" type="xs:int" minOccurs="0" />
<xs:element name="StatusSmoker" type="xs:int" minOccurs="0" />
<xs:element name="Age" type="xs:int" minOccurs="0" />
<xs:element name="QuoteExampleText" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Examples">
<xs:complexType>
<xs:sequence>
<xs:element name="Term" type="xs:int" minOccurs="0" />
<xs:element name="Premium" type="xs:decimal" minOccurs="0" />
<xs:element name="Cover" type="xs:decimal" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<getQuoteExample xmlns="">
<General diffgr:id="General1" msdata:rowOrder="0">
<Status>0</Status>
<StatusDOB>0</StatusDOB>
<StatusGender>0</StatusGender>
<StatusSmoker>0</StatusSmoker>
<Age>35</Age>
<QuoteExampleText />
</General>
<Examples diffgr:id="Examples1" msdata:rowOrder="0">
<Term>1</Term>
<Premium>9.99</Premium>
<Cover>100000</Cover>
</Examples>
<Examples diffgr:id="Examples2" msdata:rowOrder="1">
<Term>5</Term>
<Premium>19.99</Premium>
<Cover>200000</Cover>
</Examples>
<Examples diffgr:id="Examples3" msdata:rowOrder="2">
<Term>10</Term>
<Premium>29.99</Premium>
<Cover>300000</Cover>
</Examples>
<Examples diffgr:id="Examples4" msdata:rowOrder="3">
<Term>15</Term>
<Premium>39.99</Premium>
<Cover>400000</Cover>
</Examples>
<Examples diffgr:id="Examples5" msdata:rowOrder="4">
<Term>20</Term>
<Premium>49.99</Premium>
<Cover>500000</Cover>
</Examples>
</getQuoteExample>
</diffgr:diffgram>
</DataSet>
Link to comment
Share on other sites

See [a href=\"http://www.php.net/simplexml_load_file\" target=\"_blank\"]simplexml_load_file()[/a]

eg

[code]    $xml = simplexml_load_file('http://www.domain.com/yourfile.php');
    $xsl = simpleXML_load_file('myformat.xsl');
    $proc = new XsltProcessor();
    $proc->importStylesheet($xsl);
    $newxml = $proc->transformToDoc($xml);
    print $newxml->saveXML();[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.