Forum Moderators: open
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<shirt>
<name>Long Sleved></name>
<link>index/1/1</link>
<Types>
<Type>
<name>blue</name>
<link>index/1/1/1/17743/60088</link>
</Type>
<Type>
<name>green</name>
<link>index/1/1/1/1/1</link>
</Type>
<Type>
<name>red</name>
<link>index/1/1/1/2/2</link>
</Type>
<Type>
<name>yellow</name>
<link>index/1/1/1/3/3</link>
</Type>
<Type>
<name>orange</name>
<link>index/1/1/1/4/4</link>
</Type>
</Types>
</shirt>
<shirt>
<name>short sleved</name>
<link>index/1/1</link>
<Types>
<Type>
<name>light blue</name>
<link>index/1/1/1/17743/60089</link>
</Type>
<Type>
<name>green</name>
<link>index/1/2/1/1/1</link>
</Type>
<Type>
<name>red</name>
<link>index/1/2/1/2/2</link>
</Type>
<Type>
<name>yellow</name>
<link>index/1/2/1/3/3</link>
</Type>
<Type>
<name>orange</name>
<link>index/1/2/1/4/4</link>
</Type>
</Types>
</shirt>
And display it on,screen using PHP in this format,
Long Sleved, blue, index/1/1/1/17743/60088
Long Sleved, green, index/1/1/1/1/1
Long Sleved, red, index/1/1/1/2/2
Long Sleved, yellow, index/1/1/1/3/3
Long Sleved, orange<, index/1/1/1/4/4
short sleved, light blue, index/1/1/1/17743/60089
short sleved, green, index/1/2/1/1/1
short sleved, red, index/1/2/1/2/2
short sleved, yellow, index/1/2/1/3/3
short sleved, orange<, index/1/2/1/4/4
My actual xml file is a lot bigger than the example but in the same format. I hope that someone can show me how to do this. Have tried using simpleXML dom functions and others but just cant seem to do it.
Thanks
Well, what you need to do is use XSLT. However, that's not something that you will learn from a quick posting on this forum.
I recommend that you look at the wee_test series I did:
[webmasterworld.com...]
[webmasterworld.com...]
[webmasterworld.com...]
[webmasterworld.com...]
[webmasterworld.com...]
[webmasterworld.com...]
[webmasterworld.com...]
[webmasterworld.com...]
[webmasterworld.com...]
[webmasterworld.com...]
[webmasterworld.com...]
[webmasterworld.com...]
[webmasterworld.com...]
[webmasterworld.com...]
Head-Exploding Bonus Materials:
[webmasterworld.com...]
You can save yourself some reading by checking out a open source project called Json.... It is so big even Google uses it to parse XML
[json.org...]
There is a full PHP5.2 library available pre-written.
super-easy xslt transformation
<?php
// define the two ingredients...
$path_style = "myxslt.xslt";
$path_xml = "mydata.xml";// do the transformation... usually no need to alter this
$xp = new XSLTProcessor();
$xsl = new DomDocument;
$xsl->load($path_style);
$xp->importStylesheet($xsl);
$xml_doc = new DomDocument;
$xml_doc->load($path_xml);
$output = $xp->transformToXML($xml_doc);
// then...
print($output);
I spent about an hour steamlining this example and now I cut+paste it anywhere that I need to do an XML transformation - a technique which is becoming increasingly common in my work.
In order for this example to execute, I had to harass my ISP to recompile PHP with some extra config options that weren't there before... "--with-xsl[=DIR]" as described here: http://ca.php.net/xsl [ca.php.net]
if you're just getting started with XSLT, I recommend downloading a trial of <oxygen/> from [oxygenxml.com...] and play with it for a while. This forum also has a few expert participants who enjoy answering questions. Bookmark us.
cheers
I don't know if any of my ISPs have turned on PHP 5.2
I also didn't know about the PHP JSON library! Gosh, that looks useful. I've also been writing JSON "by hand". Actually, I've (on at least 2 occasions) used PHP to create XML from SQL, then used XSLT to transform that XML into JSON, which is kind of a weird thing to do when you think about it
my server is still on 5.1.2
I'm furious right now with one of my current ISPs, because they -once again- made a major configuration change that broke half my AJAX scripts. They won't install PHP 5 or MySQL 5, but make gigantic changes to the servers with no notice, then blame us when we complain.
They used to be good, then they got big, and outsourced all their tech support. I think I've had it with big ISPs. The reliability has been for s**t, and I'm sick of seven-day turnarounds on problems that could be fixed in five minutes.
</rant>