Parsing XML in Drupal
September 14, 2006 4:49 PM   Subscribe

What's the simplest way to parse XML data via XSLT in Drupal? The hitch is that I'm hosted at Dreamhost, which doesn't seem to support xslt_create().
posted by mkultra to Computers & Internet (8 answers total)
Unfortunately, it wouldn't as most shared hosts don't compile non-standard modules in.

The (lame/easy) answer to the first part of the question is to go with a VPS if you need non-standard core modules. Heck, even the default drupal XML parsing needs work (and would greatly benefit from being done in PHP5-only language). You can find ones that are comparable to shared hosting these days - and the XSLT PECL extensions are really nice.

If this is not an option:

Can you compile on your box?
If so, you could try compiling an XSLT library (ala Execute directly to xsltproc from within PHP, catching the output.

Unfortunately, I don't know of any native PHP solutions; domxml and the like are still pretty raw, and XSLT is worlds harder/slower.
posted by Vantech at 5:25 PM on September 14, 2006

I haven't done this myself, but I've got a Drupal install on Dreamhost as well; I wanted to make use of the IMAP module, which Dreamhost does not include in its PHP install. I contacted support, and they said "Oh, you can just compile your own instance of PHP and run that!"

Well, that sounded a little intimidating, so I haven't tried it yet, but I may yet (or move hosts).

There's even a page on their wiki for installing a custom version of PHP5.
posted by adamrice at 5:32 PM on September 14, 2006

Does it have to be done in Drupal? Can it be done using some other XML technology and fed to Drupal? Or, if you have to, can it be done via some non-XML dumb technology that just reads XML as text? Ugly, but it could work.
posted by AmbroseChapel at 5:58 PM on September 14, 2006

I've used SimpleXML with Dreamhost successfully. You'll need to enable PHP5 for the domain. No custom install necessary.

I haven't done it within Drupal, but my first reaction is to do the transformation within template.php and assign the results it to a PHPTemplate variable -- that is if you want to display the results in Drupal. I'd need to know more about what you're trying to do.

Or, you can import feeds too...
posted by pedantic at 6:02 PM on September 14, 2006

Best answer: For posterity, I do this on Dreamhost.

// create a DOM document and load the XSL stylesheet
$xsl = new DomDocument;

// create a DOM document and load the XML datat
$file = '[path]/_data/floorplans.xml';
$xml_doc = new domDocument;
$xml_doc->validateOnParse = true;

// import the XSL styelsheet into the XSLT process
$xp = new XsltProcessor();

// transform the XML into HTML using the XSL file
if ($html = $xp->transformToXML($xml_doc))
echo $html;
trigger_error('XSL transformation failed.', E_USER_ERROR);

posted by pedantic at 6:11 PM on September 14, 2006

Er. I lie. Not SimpleXML. I forget. Anyway, it works on standard install. Did it over a year ago.
posted by pedantic at 6:12 PM on September 14, 2006

I compiled my own PHP at Dreamhost specifically for my Drupal installation (I wanted IMAP support so I could use mailhandler).

I used the script found here. If you're comfortable using your shell account it isn't hard.

Feel free to contact me if you want help.
posted by tayknight at 6:42 PM on September 14, 2006

Response by poster: pedantic's got it (for some reason, it won't let me mark his script as Best Answer). Loading the first DomDocument via


Let me feed it the result of an http request. Thanks!

BTW, I'm integrating info from BoardGameGeek into my gaming community site, if you're wondering.
posted by mkultra at 6:54 AM on September 15, 2006

« Older Help me find a fake company's site.   |   Help me install speaker wire Newer »
This thread is closed to new comments.