Question

I have a feeling I'm being thick, but here's my problem:

I'm creating dynamic XML trees using PHP. These trees describe employee hierarchies, file directories, etc. They comprise small sections of content on a webpage. The rest of the webpage is glued together from various other sources that may be SQL based, or static text or some special presentation class. When I go to output my trees, I transform the XML into a nested <ul>. I'd like to output that <ul> without any doctype/header info. PHP's DomDocument and SimpleXML classes don't seem to allow this. Is the only option to strip the offending info off after storing the <ul> in a string?

Was it helpful?

Solution

Turns out if I put <xsl:output method="html" /> I no longer output an automatic DOCTYPE. Problem solved.

OTHER TIPS

There is a comment about this at the end of this page: http://www.php.net/manual/en/libxml.constants.php

SimpleXML automatically adds a header. There is an option to turn it off when creating an Simple XML object - its the LIBXML_NOXMLDECL but it doesn't work - there is still an open bug about it - see link at the bottom of the page above.

This is what I did in the end:

$doc = new DOMDocument('1.0');
$root = $doc->createElement('items');
$root = $doc->appendChild($root);
$title = $doc->createElement('title');
$title = $root->appendChild($title);
$text = $doc->createTextNode($item->title);
$text = $title->appendChild($text);
$items[] =  $doc->saveXML($root);

Course this doesn't give me a SimpleXml object but at least its xml and doesn't have the header..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top