Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 914
  • Last Modified:

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...

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

Open in new window

0
j789
Asked:
j789
  • 6
  • 4
1 Solution
 
käµfm³d 👽Commented:
Have you looked at SimpleXML?  http://www.w3schools.com/php/php_xml_simplexml.asp
0
 
j789Author Commented:
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-file]: I/O warning : failed to load external entity
0
 
käµfm³d 👽Commented:
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
käµfm³d 👽Commented:
It looks as though you might have to strip out the inline schema in order to be able to use simpleXML with that sample.
0
 
j789Author Commented:
When using simplexml_load_string I get the following warning...

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Extra content at the end of the document

Can you please explain in more detail what you mean...

strip out the inline schema in order to be able to use simpleXML
0
 
käµfm³d 👽Commented:
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:
<?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'));
?>

Open in new window

0
 
käµfm³d 👽Commented:
If you're less comfortable with regular expressions, using the standard string functions:

$content = substr($content, strpos($content, '<diffgr:diffgram'));
$xml = simplexml_load_string($content);

Open in new window

0
 
j789Author Commented:
Thanks for your help Kaufmed.
0
 
j789Author Commented:
Quick, accurate response.
0
 
käµfm³d 👽Commented:
NP. Glad to help  = )
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now