Jump to content

SimpleXML trouble...


MikeDXUNL

Recommended Posts

Hello,

 

What I am aiming to do, is display an XML file inside a <textarea> using the SimpleXML class.

 

Here's what I have so far, but it isn't giving me anything what I'd like it to:

<?php
  

$filename = 'data/brands_bafferts.xml';



// The file test.xml contains an XML document with a root element
// and at least an element /[root]/title.

if (file_exists($filename)) {
    $xml = simplexml_load_file($filename, 'SimpleXMLElement', LIBXML_NOCDATA);

} else {
    exit('Failed to open test.xml.');
}

echo '<br /><br /><br />';


foreach($xml->children() as $stuff) {
echo '<'.$stuff->getName().'> <br />';
echo $stuff.' <br />';

foreach($stuff->children() as $bodies) {
	echo '< BODY '.$bodies->getName().'> <br />';
					echo $bodies.' <br />';

						if($bodies->getName() != $stuff->getName()) {
						echo '</'.$stuff->getName().'> <br />';
						}
		foreach($bodies->children() as $copies) {
			echo '<'.$copies->getName().'> <br />';
			echo $copies.' <br />';
										if($copies->getName() != $bodies->getName()) {
						echo '</'.$bodies->getName().'> <br />';
						}
			}
	 }
}




?>

 

Help is appreciated!

Thanks in advance! :)

Link to comment
https://forums.phpfreaks.com/topic/161849-simplexml-trouble/
Share on other sites

<config>

<overview>

<body>
Bafferts is the result of four generations of knowledge and refinement by one of the world's foremost gin distillers, the Hayman family, who have been distilling quality gin in the heart of London for over 200 years.

The Bafferts recipe has been handed down through the Hayman family since the 1800s. To achieve its refreshing taste we infuse a special blend of botanicals that include orange peel, lemon peel, coriander, and a hint of juniper that compliment each other. The result is a lighter style of gin that is perfect for those who crave a crisp pure taste in a classic martini or gin and tonic.
</body>
</overview>

<brands>

<traditional>

<body>


Infused with a blend of four botanicals, Bafferts Gin offers a refined light taste perfect for use in martinis and other classic cocktails. 
</body>
</traditional>

<mint>

<body>


The refined, light taste of Bafferts Original infused with the flavor of mint.
</body>
</mint>
</brands>

<specs>
<bottlesize>
		<ul><li>750mL</li></ul>
	</bottlesize>
<proof>
		<ul><li>80</li></ul>
	</proof>
<accolades>
		<ul><li>Something</li></ul>
	</accolades>
<features>
		<ul><li>Something</li></ul>
	</features>
</specs>
</config>

 

That's what the XML looks like...

 

I just want that displayed in a textarea. Seperated by Nodes.

 

In the idea of this image:

http://img269.imageshack.us/img269/5046/whatiwant.jpg

Link to comment
https://forums.phpfreaks.com/topic/161849-simplexml-trouble/#findComment-853972
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.