Per Jessen wrote:
Ashley Sheridan wrote:
[/snip] :p
XSL(T)
an xslt processor, along with an XSLT stylesheet, should be used to
transform XML documents in to other XML, human readable or structured
documents.
DOM
a class implementing the DOM interface should be used to traverse,
analyse and extract information from an HTML or valid XML document for
use in a computer program or to convert values to there primitive
counterparts.
E4X
ideally E4X should be used where available as this provides native XML
support, treating xml documents as primitive types and thus providing a
faster, more acceptable way of using XML as building blocks in a
computer program.
PHP Support
As far as I am aware PHP does not have any kind of supoort for
ECMAScript let alone E4X so this can be removed from the discussion as
quickly as it was entered. Leaving just XSL and DOM.
Non programmatic XML usage:
For all non programatic usage of XML documents (ie transforming the
document in to html, a human readable document or another xml structure)
then XSLT should be used.
Examples:
-Integrating the data from an RSS feed into an (X)HTML page and
outputing it to a client application (non persistant stuctured document)
-Converting an XML Packet into an OOo document and saving it in a file
system (persistant stuctured document)
Programmatic XML Usage:
For all programmatic usage of XML, when you need to take the data from
an XML document and use node or attribute values in a program, then the
DOM API should be used.
Examples:
-Extracting the structured object data encapsulated in a SOAP response
and using it to instantiate a class for further usage. (non persitant
structured data for use by a computer program)
-Converting the data values in a structured XML document, (lets say from
the WOW Armory), into primitive values and then persiting the data into
database tables. (persitant structured data for use by a computer program)
Grey Areas:
If you are using an ORM which uses XML schemas to define data objects
then xslt may be the more appropriate choice, this would probably incur
an extra XSL transformation to then convert the ORM's schema into an object.
One could argue that XSLT could be used to transform the XML document in
to an SQL string, however this would not allow (or certainly limited
allowance of) programatic manipulation / validation of the data prior to
injection into the SQL string.
Alternatives:
Regex or string parsing on an XML document can often lead to far faster
but less reliable extraction of data for use in a script, probably so
common in PHP as it's loosley typed language :p Obviously though if the
XML document structre changes, you're pretty much stuffed - thus any
form of native or strongly typed support is a far better option.
Suggestion:
Ashley, TBH the approach I'd take (if I had time) would be to create
class(es) for the data, then create XML documents representing the
object structure of each class, write methods using the DOM API to
extract data from my XML documents and instatiate the class(es) with it.
At this point I'd have an app that need never change. Then I'd drop in a
simple XSLT stylesheet to transform the remote XML document in to my
local structured xml documents and use the XSL processor to run this
transform. Thus if ever the remote document structure changed all I'd
have to do is quickly edit the XSLT stylesheet.
But whatever you're cool with, a simple regex xml to array convertor is
normally the fastest and most transportable way of doing this (ie it'll
generally work on php 4 and 5 on any server); and when you're not using
a pre-compiled language you need to give much weight to these things.
Regards!
Nath
[omg i must be bored]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php