Help - Search - Members - Calendar
Full Version: XML Document Parsing
Weborum Webmaster Forum > Web Page Design > PHP
munnan
Hello all,
I am struck with a XML document parsing.
Following URL contain the Xml functions.
http://195.57.250.36/barceloDS/interface/xml
The method through which I am trying to access xml function in PHP is given below. But I am unable to get these functions to get data in PHP.
[php]
<?php
// includes nusoap classes
require('nusoap.php');

$l_aParam="<?xml version='1.0' encoding='ISO-8859-1'?>
<barceloDS_requests>
<request type='availability list' id='1'>
<language_code>ING</language_code>
<agency>
<primary>78</primary>
<secondary>88</secondary>
<detail>888</detail>
<branch>1</branch>
</agency>
<contract></contract>
<check_in_date>20051201</check_in_date>
<check_out_date>20051207</check_out_date>
<location>
<destination_code>PMI</destination_code>
<zone_code></zone_code>
</location>
<establishment>
<code></code>
<category></category>
</establishment>
<board_type_code></board_type_code>
<occupancy>
<adults>2</adults>
<children>0</children>
<rooms>1</rooms>
</occupancy>
</request>
</barceloDS_requests>";

//print($l_aParam);

// set parameters and create client

$l_oClient = new soapclient(‘http://195.57.250.36/barceloDS/interface/xml’);

// call a webmethod
$l_stResult = $l_oClient->call('availability',$l_aParam);
/*”I think the problem area is this”*/

print_r($l_stResult);

if ($l_oClient->getError()) {

echo("Error Found :".$l_oClient->getError());
}
else{
echo("No Error Found");
}
?>
[/php]


Following is the sample code in ASP that company had provided me that is working fine.

<%
Dim xml

xml = "xml=<?xml version='1.0' encoding='ISO-8859-1'?>" + _
"<barceloDS_requests>" + _

"<request type='availability list' id='1'>" + _
" <language_code>ING</language_code>" + _
" <agency>" + _
" <primary>888</primary>" + _
" <secondary>88</secondary>" + _
" <detail>888</detail>" + _
" <branch>1</branch>" + _
" </agency>" + _
" <contract></contract>" + _
" <check_in_date>20041201</check_in_date>" + _
" <check_out_date>20041207</check_out_date>" + _
" <location>" + _
" <destination_code>PMI</destination_code>" + _
" <zone_code></zone_code>" + _
" </location>" + _
" <establishment>" + _
" <code></code>" + _
" <category></category>" + _
" </establishment>" + _
" <board_type_code></board_type_code>" + _
" <occupancy>" + _
" <adults>2</adults>" + _
" <children>0</children>" + _
" <rooms>1</rooms>" + _
" </occupancy>" + _
"</request>" + _

"</barceloDS_requests>"

'==================================
'Response.Write xml
'Response.End
'==================================


Dim xmlHTTP, URLPath

Set xmlHTTP = Server.Createobject("MSXML2.ServerXMLHTTP")

' url test server
URLPath = "http:// 194.224.184.162/barceloDS/interface/xml"

xmlHTTP.open "POST", URLPath, False
xmlHTTP.SetRequestHeader "Content-type","application/x-www-form-urlencoded"

xmlHTTP.send(xml)

'strXMLOut = xmlHTTP.responseText
strXMLOut = xmlHTTP.ResponseXML.xml

'==================================
'Response.Write(strXMLOut)
'Response.End
'==================================

Dim xmlDoc

Set xmlDoc = Server.CreateObject("Msxml2.DOMDocument")
xmlDoc.async = False
xmlDoc.load ("strXMLOut")
xmlDoc.validate

If xmlDoc.parseError.errorCode <> 0 Then
Response.Write("A parse error occurred.<br>")
Response.Write("Error Code is: ")
Response.Write(xmlDoc.parseError.errorCode)
Response.Write("<br>")
Response.Write("The reason is: ")
Response.Write(xmlDoc.parseError.reason)
Response.Write("<br>")
Response.Write("Error in Line No.: ")
Response.Write(xmlDoc.parseError.Line)
Response.Write("<br>")
Response.Write("Position: ")
Response.Write(xmlDoc.parseError.linepos)
Response.Write("<br>")
Response.Write("Error in URL: ")
Response.Write(xmlDoc.parseError.url)
Response.Write("<br>")
Response.End()

End If
%>





I am unable to retrieve data through my php script(that I have provided above) ,please help me out by telling the ways to retrieve data through this xml document.
Thanking you in anticipation,
Munnan
Josh
Isn't response.write asp?
mawrya1
Sounds like you want something like following, which submits a string of xml to a php script on the server, the php then writes the received string into a local file, but you could do anything you want with it. Finally, the php echos a reply back to the html page that sent the xml string and the reply is displayed on the html page.

Running php 5 on apache 2, both files should work as-is if you dump them in the same directory, you could put them on different servers if you like, just be sure to change POST url in the html page - see comment in html code.

Note, the posttest.html code below only works in IE, but Mozilla Browsers have the ability to do XMLHTTP posts just as easily - the info is widely available on the web, just google: mozilla xmlhttp.

over and out, mawrya

======================
CLIENT SIDE HTML - posttest.html
======================

<html>
<head><title>post it pages</title></head>
<body>
<script>
function postXML()
{
//Create string of XML
var sXML="<test>its alive!!</test>";

//Create new XMLHTTP object
var msobj = new ActiveXObject("Microsoft.XMLHTTP");
msobj.open("POST", "posttest.php",false); //Replace "posttest.php" with "http://www.someserver.com/somescript.php" as needed.
msobj.setRequestHeader("Content-Type", "text/xml");
msobj.setRequestHeader("Content-Length", sXML.length);
//Send XML string to PHP script file/url specified on line 12.
msobj.send(sXML);

//Read and display reply from PHP script
var ans = msobj.responseText;
document.getElementById('text1').innerHTML=ans;
}
</script>
<div id=text1></div>
<input type=button value="click me" onclick="postXML()">
</body>
</html>


=====================
SERVER SIDE PHP - posttest.php
=====================

<?php
$sXML = $GLOBALS['HTTP_RAW_POST_DATA'];

// Open a text file and erase the contents if any
$fp = fopen("myXMLfile.xml", "w");

// Write the data to the file
fwrite($fp, $sXML);

// Close the file
fclose($fp);

//Send a reply back to the webpage that submitted the post data.
echo "Document Received Successfully.";
?>
mawrya1
Or, maybe you're looking for something similar to another post I read recently. You need to have the curl library going in PHP.

mawrya


Here's a copy of the post:



mmm at [blockspam] turkmenweb dot com
15-Dec-2003 07:49
I know that many people suffer from cURL when trying to send XML data. I solved this problem and want to share it with you:

I was trying to send SMS messages with a SMS service provider. They gave me the following ASP code, where you send data as XML and receive a response in XML as well:

url = "http://...someaddress/somefile.asp";
xmldata ="<XMLtag1>many other tags, data here</XMLtag1>";
Set ob = Server.CreateObject("Msxml2.XMLHTTP")
ob.Open "POST",url,false
ob.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
ob.Send xmldata
...then recieve code was here...

This is done in PHP using cURL library in this way:

<?php
$XPost = "<XMLcontent>sameas above</XMLcontent>"
$url = "..same URL as above..";
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 4); // times out after 4s
curl_setopt($ch, CURLOPT_POSTFIELDS, $XPost); // add POST fields
$result = curl_exec($ch); // run the whole process
echo $result; //contains response from server
?>

Some say that you should use CURLOPT_CUSTOMREQUEST, CURLOPT_HTTPHEADER and etc. to perform this task , as you can see you don't need those at all.

Hope it will help those who tries to simulate Msxml2.XMLHTTP or simply try sending XML data over PHP.

Regards,
Muhammed Mamedov

Jay
hi,

i am trying your script for posting xml document to a server and getting response back in Interent explorer as below:

It appears as simple text in browser
--
<check><results><rate_fixed>A</rate_fixed><rate_adaptive>G</rate_adaptive><incompatible_code>Z</incompatible_code><exchange_code>LWHOU</exchange_code><exchange_name>HOUNSLOW</exchange_name><exchange_state>E</exchange_state><exchange_readydate></exchange_readydate><exchange_trigger></exchange_trigger><postcode_match>N</postcode_match></results><error><error_number>0</error_number><error_desc/></error></check>
---


But I am not able to catch data generated form this.
Can you please help me how can I extract data from this.

It would be much help.

Thanks waiting soonest response...

sjthomas
If you just want to get the data out quickly and easily theres really no need to use something like SOAP. And surely the whole point of processing the XML at the server side is to ensure it works cross browser?

Anyway, I wrote a simple tutorial a while back:
http://www.tazr.com/view.php?area=article&...al-050605102231

which may help you out. And as Willy pointed out, its considered bad etiquette to cross post questions.
Jay
hi all,

i am posting a xml to asp page and receiving an xml outpout.
I am trying to achieve this using the below codes but it doesn't work

Can you please help me, where i am missing or make any mistake.

Please help me...
<?
$url = "https://core.managedbroadband.co.uk/asp-com/btchecker.asp";
$XPost = "<linecheck><sp><username>erer</username><password>rererer</password><spid>xxx</spid></sp><check><telephone>4343434343</telephone><postcode>3434343434</postcode></check></linecheck>";
$header = "Content-type: text/xml \r\n";
$header .= "Content-length: ".strlen($post_string)." \r\n";
$header .= $XPost;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_POSTFIELDS, $header);

$result = curl_exec($ch);
echo $result;
?>


Thanks! hope to hear soon from you...
Jay
Guys,


please help me on this...

thanks
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.