Using XML to format text

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Etrai
Forum Newbie
Posts: 3
Joined: Sat Sep 29, 2007 9:27 am
Location: Linköping, Sweden

Using XML to format text

Post by Etrai »

Hi!
I'm making a homepage for a company right now and thay want it to be easy for them to change the content without having to contact me or my "associates" to get it done. So now I'm at somewhat of a crossroads and I kinda need a nudge in one direction or the other. My problem is this:
The textual content for any given page is stored in an XML file (at the moment). For example "home.xml" which is structured something like this:

Code: Select all

<page>
   <paragraph>Here be some text.</paragraph>
   <paragraph>Here be more text.</paragraph>
</page>
Within the paragraphs I want to enable some sort of text formatting in the form tags, for instance a <bold></bold> tag for making the text bold.

Code: Select all

<page>
   <paragraph>Here be some text, <bold>and it's bold</bold>.</paragraph>
   <paragraph>Here be more text.</paragraph>
</page>
The problem I'm having is that when I parse the XML-file I have no idea where the formatting tags are located within the paragraph tags, and I would like to keep the <> identifiers for tags _and_ not have to parse the document more than once. (I have a solution that would take two passes and use BB-codish syntax.)
Any ideas? Do I need to explain it better? ;)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Are you using one of the XML parsing libraries available for PHP (as natives)? e.g SimpleXML, DOM...
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

You might also be interested in XSL.

see also:
http://www.w3schools.com/xsl/
http://de2.php.net/xsl
Etrai
Forum Newbie
Posts: 3
Joined: Sat Sep 29, 2007 9:27 am
Location: Linköping, Sweden

Post by Etrai »

feyd wrote:Are you using one of the XML parsing libraries available for PHP (as natives)? e.g SimpleXML, DOM...
I'm using SimpleXML at the moment, and I have looked into the xml parser functions and briefly into the DOMDocument class. I know that what I want to do should not be (is not?) possible with SimpleXML
volka wrote:You might also be interested in XSL.

see also:
http://www.w3schools.com/xsl/
http://de2.php.net/xsl
I'll definatly have a look see atleast, thanks =)
Etrai
Forum Newbie
Posts: 3
Joined: Sat Sep 29, 2007 9:27 am
Location: Linköping, Sweden

Post by Etrai »

Now I've had some time to look at XSL and it doesn't seem to do what I need. Atleast not in a simple enough fashion =/
Any other recommendations or ideas?
Post Reply