The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

XML parsing into a DOM + efficiency questions

hey guys,

Alright, what I would like to do is parse an XML file, and place it all into a tree structure (DOM I think it's called).

Right, I know that there are PHP functions to do this, however they are experimental. Also, I bet not a lot of hosts support them. So, I would like to do it myself. However, there are will be 2 differnent kinds of tags, what I call 'structure' tags, and 'style' tags. Lemme give you an example

Right, I'm sure you get the general idea, so the only 'style' tags in there would be '<p>' and '<b>', the rest are structure tags.

Now, what would be the difference? Well, when the XML document is parsed, the style tags would just be replaced with HTML in order to produce the right effect and would be included as text in the "DOM". Now, let me further the idea of the DOM (what I view it as at least)

Apparently PHP's OOP is quite inefficient. For normal use of objects (for example a database abstraction layer) performance is not an issue, but the system you are suggesting could have potentially hundreds of objects nested within each other. I've not seen any benchmarks about this but it is something you should definitely bare in mind.

There is already a PHP-only (i.e not relying on PHP's built in XML handling functions) solution for XML which you may want to have a look at:

Best solution is XSL/XSLT

I am also considering how to best use xml in my site.
After long time reading materials from the web, i think the best solution is XML+XSL+XSLT.
For your example, i think you can write a xsl file, in which all style tags are not processed, say for body:

and you can then use xslt extension of PHP to process it.
For more info, please refer to php manual.
after 4.10, the xslt in php is a generic solution other than sabletron in older versions, so the codes are different.
xslt_process() page gives some good examples.

Yeah, I looked at XSLT. It is a good system, only there are a few drawbacks. Those being that not many hosts support XSLT, there are a few, but not really enough. I want to make a script that is useable on a good majority of servers. Also, XSLT doesn't make it too easy to make a template that would be easy to make content spread on multiple pages. I mean, it wouldn't be easy for the average user, and I'm making a script that not the most tech savy user is going to be using.

I decided to opt for the normal XML functions, and make my own parser and validator, that would only parse the xml when it is submitted to the CMS, then converted partially into html, and then stuck into the rest of the template when the page is loaded.