Hi Everybody,
Someone can help me please! I'm parsing a xml.file to translate it to php.file but I cant display the result?
For better comprehension, here's the links:
1.link of my xml.file: http://www.xxxxx.com/xml/20.xml
2.link of my parsed php.file: http://www.xxxxx.com/xml/20.php
3.link of my DTD.file: http://www.xxxxx.com/xml/ICECAT-interface_response.dtd
And I would like to display a result like this :
http://prf.icecat.biz/index.cgi?product_id=20;mi=start;smi=product;shopname=digilooxcat
So can somebody help me please, cause I'm beginner in XML!! :-)
Here is the php code of my page /20.php:
<?php
require("MagicParser.php");
function myRecordHandler($record)
{
// This is where you write your code to process each record, such as loading a database
// Here we just display the record contents using PHP's internal print_r() function
print_r($record);
}
MagicParser_parse("20.xml","myRecordHandler","xml|ICECAT-INTERFACE/");
?>
Dear David,
This helps me a lot!!
Thank you very much!! You're a genius ;)-
Cheers.
Sabri
Hi,
To process XML such as this requires two steps. First, you need to parse the file with the format string in your existing 20.php to get the top level product information. Secondly, you then need to parse it with another format string to extract the features.
I've written a demo file to show what I mean. Here it is running on this server:
http://www.magicparser.com/examples/20.php
Here's the source:
<?php
header("Content-Type: text/html;charset=utf-8");
require("MagicParser.php");
function myProductRecordHandler($record)
{
print "<h2>".$record["PRODUCT-NAME"]."</h2>";
print "<img src='".$record["PRODUCT-LOWPIC"]."' />";
print "<p>".$record["PRODUCT/PRODUCTDESCRIPTION-LONGDESC"]."</p>";
}
// first parse to extract the top level product information
MagicParser_parse("20.xml","myProductRecordHandler","xml|ICECAT-INTERFACE/");
print "<h3>Features</h3>";
function myFeatureRecordHandler($record)
{
print "<p>";
print $record["FEATURE/NAME-VALUE"].": ";
print $record["PRODUCTFEATURE-VALUE"]." ";
print $record["FEATURE/MEASURE-SIGN"];
print "</p>";
}
// second parse to extract the feature list
MagicParser_parse("20.xml","myFeatureRecordHandler","xml|ICECAT-INTERFACE/PRODUCT/PRODUCTFEATURE/");
?>
If you compare the values such as "PRODUCT-LOWPIC" in this source code to the output of your first version, you will see that the values used to index the $record array match the values you can see in the output. So, to add more of the information from the XML to this version simply add code to index the $record array with the value you want.
Hope this helps get you started...
Cheers,
David.