Page 1 of 1

manipulating XML

Posted: Fri Apr 09, 2004 6:38 am
by kyokutan
Hi guys,

i was wondering how to parse XML using php and manipulate the data at the same time. I have been able to parse the xml, but i need to move data from one tag, to a different position.

eg.
<row id ="1">
<url>portal.php</url>
<display_url>http://www.devnetwork.net</display_url>
<title>php forum</title>
<description>this is a php forum</description>
</row>
<row id ="2">
<url>http://www.php.net</url>
<display_url>http://www.devnetwork.net</display_url>
<title>php forum</title>
<description>PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML</description>
</row>

How can i render this xml so that i move the display_url after the description..??

cheers.

Posted: Fri Apr 09, 2004 3:53 pm
by twigletmac
You can use XSL to rewrite the XML in a slightly different arrangement.

Mac

Posted: Fri Apr 09, 2004 5:04 pm
by patrikG
XSL would be the cleanest solution. An alternative, and a quite complicated one, would be to use the xpath extension to get the various nodes and then use PHP's XML-DOM functions to generate a new XML document.

That would be so much extra work (for both you and the server) that is worthwhile getting into XSL.

Posted: Fri Apr 09, 2004 5:14 pm
by twigletmac
I've tried to repress my memories of PHP's XML-DOM functions, they're painful 8O

Mac

Posted: Fri Apr 09, 2004 5:18 pm
by patrikG
Very vivid for me... I took on a legacy project which included that - in fact, generating XML with PHP's DOM is not too bad, but the parsing... ick. It hurts. :|

Posted: Fri Apr 09, 2004 5:26 pm
by PrObLeM