Jump to content

Archived

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

bullchina

xml parsing and smarty templates

Recommended Posts

I tried posting this two days ago, but it never got answered...

I just want to learn how to parse xml that has more than three levels of depth in php, and display the results, sorted, in a smarty template. thanks for any advice you have to offer

Share this post


Link to post
Share on other sites
What results do you want to display? What do you want to parse the XML for? Why not simply use an XSL stylesheet to do your transformation, if that is indeed what you are doing? That's more standard than Smarty, anyway. :)

Share this post


Link to post
Share on other sites
well i have this xml code:

[code]<?xml version="1.0" encoding="ISO-8859-1"?>
<projects>
<project>
<name>Test Project</name>
<date>2006</date>
<location>Barcelona, Spain</location>
<description><![CDATA[<p>This is a test project description with two paragraphs</p><p>this is the second paragraph</p> ]]></description>
<type>Corporate Garden</type>
<info>this is a field for extra information, about the clients, the size, price, etc...</info>
<directory>test</directory>
<images>
<image name="test.porch.jpg" title="this is image 1." />
<image name="test.firstfloor.jpg" title="this is image 2." />
<image name="test.firstfloor2.jpg" title="this is image 2." />
</images>
<files>
<file />
<file />
</files>
<status>built</status>
</project>
</projects>[/code]

and i want to be able to display the projects (there will be a lot of them) sorted by different parameters, like by type, by date, by location, and also be able to print out image thumbnails, hyperlinks to the big images, etc...

I also know very little about XSL, and i wouldn't even know where to start. I'm just learning smarty, and i have the whole rest of the site working in smarty.

Share this post


Link to post
Share on other sites
This is a classic case for XSL. All I can suggest is to parse it in XSL to get the desired output, then assign the string to Smarty.

Here is a starting resource on XSLT: http://www.w3schools.com/xsl/

Share this post


Link to post
Share on other sites
so I will need to learn xPath as well? How long do you think all of this will take to absorb and get up and running? thanks for your help, i really appreciate it...

Share this post


Link to post
Share on other sites
Kind of depends how fast you learn things. It can be anywhere from fairly simple to magnificently comjplicated, depending on what you need to do.

XPath really isn't all that hard; it is XSLT that gets difficult.

Share this post


Link to post
Share on other sites

×

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.