homepage Welcome to WebmasterWorld Guest from 23.20.77.156
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP and XML
Using XML to store site content
Red_Eye




msg:3222077
 11:30 am on Jan 17, 2007 (gmt 0)

I have a site where I want to generate the content from an XML file like this

<projects>
<project id="1">
<title>this is the title for project 1</title>
<description>this is the description</description>
</project>
<project id="2">
<title>this is the title for project 2</title>
<description>this is the description</description>
</project>
</projects>

I want to get the project id from the url (no problem here) then open the xml file and get the information for this project.

I am having problems getting my head around how to do this with PHP (its a long time since I used it) this is with php 4.

I have tried using an xslt to transform the xml which works but i might want the description to contain <p> tags.

So I think that I need to open the xml file get the information and then load it into php variables that I can manipulte before they are displayed.

Any suggestions

 

ahmedtheking




msg:3222128
 12:41 pm on Jan 17, 2007 (gmt 0)

Firstly, may I ask, why are you storing your data in XML?

Secondly, the best way to do it is using PHP's XML functions found here: [uk2.php.net...]

[edited by: coopster at 3:50 pm (utc) on Jan. 17, 2007]
[edit reason] removed link to non-authoritative site [/edit]

Red_Eye




msg:3222132
 12:51 pm on Jan 17, 2007 (gmt 0)

The website is a very simple website that the customer wants to update themselves. They have no experiance of html etc. Having discussed it with them and shown them a sample xml file they would be happy to edit this and then upload this one xml file, rather than edit html etc...

So I have create the template in PHP all I need to do now is hook up the data.

ahmedtheking




msg:3222145
 12:58 pm on Jan 17, 2007 (gmt 0)

It'll still be easier to make a little CMS through a database or even through a text file! But anyhoo, yeah that's how to parse XML! I mean you don't even need PHP, you can use XSLTs! It doesn't matter if the XML contains html tags, you just 'include' the data within a <div>

Red_Eye




msg:3222164
 1:15 pm on Jan 17, 2007 (gmt 0)

I think that you are right xml looks like the idea tool for this job but getting it to work is a real pain
I think that I might go back to xslt one last time before I try something different

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved