Page 1 of 1
Read ASP.NET generated XML
Posted: Wed May 12, 2004 3:27 am
by seevali
I need to post some data to an external ASP page on a remote site and then it will generate a XML file. This XML file generate an error code in the case of Error of the data posted and a URL for a site in the case of Success. Upon reading i have to redirect user to the particular site or display an error message. Everything has to be done while keeping user on the same page of my site. Any ideas how to do this ?
Posted: Wed May 12, 2004 4:04 am
by patrikG
Either use an invisible frame or an iframe to interact with the ASP-page.
One questions: why so complicated? PHP can generate beautiful XML, even with just the DOM.
Posted: Thu May 13, 2004 12:28 am
by seevali
Thanks for the help. I think i haven't explained well about the problem. It's like this.
I am doing music download site say ABC.COM. Once user pay for music and click download link , some information like username,password and music id etc should be posted to an ASP page on a remote server say XYZ.COM. Then i should read the XML file generated by this ASP page.
In the case of success XML file returns the URL of the server where actual music file stored. In case of error it will return the error code and i should display user an error message. While keeping user ABC.COM site i have to all these things. Then i should redirect user to actual music site which is XYZ.com by opening a new window. Then user can download or play from there itself. Please advise me, since I am new to PHP XML programming.
Posted: Thu May 13, 2004 10:02 am
by Weirdan
What does xml generated by remote server look like? Could you provide us with examples of xml responses for both successful and failed requests?
Posted: Thu May 13, 2004 11:23 am
by launchcode
seevali - how should the data be passed to the ASP script? Do you send it on the query string, or via a form POST?
Posted: Fri May 14, 2004 3:38 am
by patrikG
Regarding parsing XML - make sure you have XPath module installed (see manual for how to).
If you'd need to generate XML, the DOM is usually sufficient and, since PHP 4.34 - stable. Don't use the DOM to parse XML: it's like eating a sandwich with rotten chicken meat. A pain in the butt - and don't let people tell you that 15-dimensional arrays are the bee's knees.
When I started XML I couldn't find any helpful tutorials on the web (XPath does need some getting used to) - so I'd recommend buying a book to learn about the ins and outs.
Stuff I found useful:
http://www.devshed.com/index2.php?optio ... &hide_js=1
http://www.xml.com/pub/rg/143
http://www.phpbuilder.com/columns/matt20001228.php3
Enjoy

Posted: Fri May 14, 2004 4:47 am
by seevali
Many thanks all of you guys. I found out a way to resolve this prob. I use CURL function to post information to ASP page. Then it returns me XML file as a string. Then i load that string into memore using domxml_open_mem (). and perform the rest.
Am expecting another additional advice from you guys, is there an efficient way to parse very large XML file (around 100 MB) file over the network. I used DOM but it's very bad in terms of performance. Earlier i used SAX since i just want to read the XML and populate the Mysql database. but it also gave me some problem when data element contain character like '&'. Any ideas..
Posted: Fri May 14, 2004 5:04 am
by patrikG
As I said in my earlier post: don't use the DOM to parse XML, only to generate.
To parse XML, I use xPath (see
Sablotron). Here's a code example
Code: Select all
<?php
$xml='<MY_SERVICE>
<MERCHANDISE>
<SERVICE TYPE="books">
<NAME>Ulysses</NAME>
</SERVICE>
<SERVICE TYPE="books">
<NAME>The Poisonwood Bible</NAME>
</SERVICE>
<SERVICE TYPE="cars">
<NAME>Van</NAME>
</SERVICE>
<SERVICE TYPE="vehicle sans wheels">
<NAME>UFO</NAME>
</SERVICE>
</MERCHANDISE>
</MY_SERVICE>';
echo "<h4>XML</h4><xmp>";print_r(parse_XML($xml));echo"</xmp>";
function node_content($node,$attribute="content"){
foreach($node->nodeset as $content){
$return[] = $content->{$attribute};
}
return $return;
}
function parse_XML($xml){
//needs PHP's xPath extension installed
$dom =domxml_open_mem($xml);
$calcX =&$dom->xpath_new_context();
$xml_parsed["merchandise"]=node_content($calcX->xpath_eval("//MERCHANDISE/SERVICE/NAME/text()"));
$xml_parsed["service"]=node_content($calcX->xpath_eval("//MERCHANDISE/SERVICE/attribute::TYPE",$calcX),"value");
return $xml_parsed;
}
?>
The code above returns:
XML
Array
(
[merchandise] => Array
(
[0] => Ulysses
[1] => The Poisonwood Bible
[2] => Van
[3] => UFO
)
[service] => Array
(
[0] => books
[1] => books
[2] => cars
[3] => vehicle sans wheels
)
)