View previous topic
::
View next topic
|
Author |
Message |
ramon fincken Site's programmer
 Get a free globally recognized avatar It's free!
Joined: 03 Aug 2007 Posts: 403 Location: A'dam/Diemen, The Netherlands
|
Posted: Mon Mar 17, 2008 9:37 pm Post subject: [solution] Parsing XML to an array |
|
|
Allrighty so you client wanted XML to be imported or read using your PHP application and you got stuck on the actual 'reading' of XML?
Here's a solution to parse / convert the XML into a nice readable PHP array:
http://keithdevens.com/software/phpxml
Try it yourself using this webbased demo!
http://keithdevens.com/software/phpxml/xml-to-php
ps: read the next post if you have PHP5 or access to the simpleXML functions-set !
Last edited by ramon fincken on Tue Jun 10, 2008 12:15 pm; edited 1 time in total |
|
Back to top |
|
 |
Google adsense Advertisement
|
Posted: Mon Mar 17, 2008 9:37 pm Post subject: [solution] Parsing XML to an array |
|
|
Advertisement
|
|
Back to top |
|
 |
GravityForms Advertisement
|
Posted: Mon Mar 17, 2008 9:37 pm Post subject: [solution] Parsing XML to an array |
|
|
Advertisement
 |
|
Back to top |
|
 |
ramon fincken Site's programmer
 Get a free globally recognized avatar It's free!
Joined: 03 Aug 2007 Posts: 403 Location: A'dam/Diemen, The Netherlands
|
Posted: Fri Jun 06, 2008 7:36 am Post subject: Re: [solution] Parsing XML to an array |
|
|
Perhaps even better:
http://us2.php.net/manual/en/simplexml.examples.php
Code: | <?php
$xmlstr = <<<XML
<?xml version='1.0' standalone='yes'?>
<movies>
<movie>
<title>PHP: Behind the Parser</title>
<characters>
<character>
<name>Ms. Coder</name>
<actor>Onlivia Actora</actor>
</character>
<character>
<name>Mr. Coder</name>
<actor>El ActÓr</actor>
</character>
</characters>
<plot>
So, this language. It's like, a programming language. Or is it a
scripting language? All is revealed in this thrilling horror spoof
of a documentary.
</plot>
<great-lines>
<line>PHP solves all my web problems</line>
</great-lines>
<rating type="thumbs">7</rating>
<rating type="stars">5</rating>
</movie>
</movies>
XML;
?>
|
Code: | <?php
include 'example.php';
$xml = new SimpleXMLElement($xmlstr);
echo $xml->movie[0]->plot; // "So this language. It's like..."
?>
|
Code: | <?php
include 'example.php';
$xml = new SimpleXMLElement($xmlstr);
/* Access the <rating> nodes of the first movie.
* Output the rating scale, too. */
foreach ($xml->movie[0]->rating as $rating) {
switch((string) $rating['type']) { // Get attributes as element indices
case 'thumbs':
echo $rating, ' thumbs up';
break;
case 'stars':
echo $rating, ' stars';
break;
}
}
?>
|
|
|
Back to top |
|
 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|