Jump to content


Photo

xml parsing and smarty templates


  • Please log in to reply
5 replies to this topic

#1 bullchina

bullchina
  • Members
  • PipPip
  • Member
  • 19 posts
  • LocationHouston

Posted 27 August 2006 - 11:33 AM

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

#2 devbanana

devbanana
  • Members
  • PipPip
  • Member
  • 18 posts
  • LocationI don't know, but all I can see is this computer...

Posted 27 August 2006 - 03:05 PM

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. :)
Programming in PHP since 1882. Oh wait, computers weren't around that long, huh....
Hey, while we're here, would you mind giving me some suggestions on my PHP framework?

#3 bullchina

bullchina
  • Members
  • PipPip
  • Member
  • 19 posts
  • LocationHouston

Posted 27 August 2006 - 04:12 PM

well i have this xml 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>

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.

#4 devbanana

devbanana
  • Members
  • PipPip
  • Member
  • 18 posts
  • LocationI don't know, but all I can see is this computer...

Posted 27 August 2006 - 04:17 PM

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/
Programming in PHP since 1882. Oh wait, computers weren't around that long, huh....
Hey, while we're here, would you mind giving me some suggestions on my PHP framework?

#5 bullchina

bullchina
  • Members
  • PipPip
  • Member
  • 19 posts
  • LocationHouston

Posted 27 August 2006 - 05:35 PM

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...

#6 devbanana

devbanana
  • Members
  • PipPip
  • Member
  • 18 posts
  • LocationI don't know, but all I can see is this computer...

Posted 27 August 2006 - 05:51 PM

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.
Programming in PHP since 1882. Oh wait, computers weren't around that long, huh....
Hey, while we're here, would you mind giving me some suggestions on my PHP framework?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users