j789
asked on
Read a .net dataset using php
I'm trying to use a web-service that has been written in C# .NET and returns a .NET dataset (see response below). The website is on a PHP platform. As you can see the information is there I just would like to know how to extract the values. Thanks.
Here's the response...
Here's the response...
<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="LoginDet"><xs:element name="LoginDet" msdata:isdataset="true" msdata:maindatatable="Table" msdata:usecurrentlocale="true"><xs:complextype><xs:choice minoccurs="0" maxoccurs="unbounded"><xs:element name="Table"><xs:complextype><xs:sequence><xs:element name="LoginId" type="xs:int" minoccurs="0"><xs:element name="PasswordReminderTypeId" type="xs:int" minoccurs="0"><xs:element name="EmailId" type="xs:int" minoccurs="0"><xs:element name="LoginName" type="xs:string" minoccurs="0"><xs:element name="Password" type="xs:string" minoccurs="0"><xs:element name="MasterLoginId" type="xs:int" minoccurs="0"><xs:element name="NameId" type="xs:int" minoccurs="0"><xs:element name="UserEdit" type="xs:boolean" minoccurs="0"><xs:element name="Email" type="xs:string" minoccurs="0"><xs:element name="FullName" type="xs:string" minoccurs="0"><xs:element name="HasOwnership" type="xs:boolean" minoccurs="0"></xs:element></xs:element></xs:element></xs:element></xs:element></xs:element></xs:element></xs:element></xs:element></xs:element></xs:element></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"><logindet xmlns=""><loginid>2223344432</loginid><passwordremindertypeid>342</passwordremindertypeid><emailid>313734</emailid><loginname>2222</loginname><password>11111</password><nameid>1079622</nameid><useredit>false</useredit><email>test@emailaddress.com</email><fullname>Mr Somebody</fullname><hasownership>true</hasownership><table diffgr:id="Table1" msdata:roworder="0"></table></logindet></diffgr:diffgram>
Have you looked at SimpleXML? http://www.w3schools.com/php/php_xml_simplexml.asp
ASKER
Hi Kaufmed, thanks for your response. I have looked at SimpleXML before but I get the following error when using simplexml_load_file...
Warning: simplexml_load_file() [function.simplexml-load-f ile]: I/O warning : failed to load external entity
Warning: simplexml_load_file() [function.simplexml-load-f
Do you have the XML stored in a file on your server? I got the impression you would have the data as a string in your code. If so, then I believe you should be using simplexml_load_string. My last post is a bit misleading in that regard. The next page, http://www.w3schools.com/php/php_ref_simplexml.asp , gives you a list of functions you can use with this library.
It looks as though you might have to strip out the inline schema in order to be able to use simpleXML with that sample.
ASKER
When using simplexml_load_string I get the following warning...
Warning: simplexml_load_string() [function.simplexml-load-s tring]: Entity: line 1: parser error : Extra content at the end of the document
Can you please explain in more detail what you mean...
Warning: simplexml_load_string() [function.simplexml-load-s
Can you please explain in more detail what you mean...
strip out the inline schema in order to be able to use simpleXML
The first part of your XML sample is the schema. If this is how you receive the XML from the web service, then you have an inline schema, which just means that the schema is embedded into the XML. In my testing, simpleXML did not function as expected when the schema was included. I used a simple preg_replace to strip it out.
Here is what I tested with:
Here is what I tested with:
<?php
$content='<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="LoginDet"><xs:element name="LoginDet" msdata:isdataset="true" msdata:maindatatable="Table" msdata:usecurrentlocale="true"><xs:complextype><xs:choice minoccurs="0" maxoccurs="unbounded"><xs:element name="Table"><xs:complextype><xs:sequence><xs:element name="LoginId" type="xs:int" minoccurs="0"><xs:element name="PasswordReminderTypeId" type="xs:int" minoccurs="0"><xs:element name="EmailId" type="xs:int" minoccurs="0"><xs:element name="LoginName" type="xs:string" minoccurs="0"><xs:element name="Password" type="xs:string" minoccurs="0"><xs:element name="MasterLoginId" type="xs:int" minoccurs="0"><xs:element name="NameId" type="xs:int" minoccurs="0"><xs:element name="UserEdit" type="xs:boolean" minoccurs="0"><xs:element name="Email" type="xs:string" minoccurs="0"><xs:element name="FullName" type="xs:string" minoccurs="0"><xs:element name="HasOwnership" type="xs:boolean" minoccurs="0"></xs:element></xs:element></xs:element></xs:element></xs:element></xs:element></xs:element></xs:element></xs:element></xs:element></xs:element></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"><logindet xmlns=""><loginid>2223344432</loginid><passwordremindertypeid>342</passwordremindertypeid><emailid>313734</emailid><loginname>2222</loginname><password>11111</password><nameid>1079622</nameid><useredit>false</useredit><email>test@emailaddress.com</email><fullname>Mr Somebody</fullname><hasownership>true</hasownership><table diffgr:id="Table1" msdata:roworder="0"></table></logindet></diffgr:diffgram>';
$xml = simplexml_load_string(preg_replace('#<(xs:schema).+?</\1>\s*#s', '', $content));
var_dump($xml->xpath('/diffgr:diffgram/logindet/loginid'));
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help Kaufmed.
ASKER
Quick, accurate response.
NP. Glad to help = )