Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies


Using XML to store site content



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

10+ Year Member

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

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

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


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

WebmasterWorld Senior Member 10+ Year Member

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]


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

10+ Year Member

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.


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

WebmasterWorld Senior Member 10+ Year Member

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>


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

10+ Year Member

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

Featured Threads

Hot Threads This Week

Hot Threads This Month