<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Generating (X)HTML Documents Using DOMDocument In PHP</title>
	<atom:link href="http://www.ultramegatech.com/2009/07/generating-xhtml-documents-using-domdocument-in-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ultramegatech.com/2009/07/generating-xhtml-documents-using-domdocument-in-php/</link>
	<description>Web development blog</description>
	<lastBuildDate>Wed, 11 Apr 2012 03:57:31 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Matthijs Kooijman</title>
		<link>http://www.ultramegatech.com/2009/07/generating-xhtml-documents-using-domdocument-in-php/comment-page-1/#comment-1759</link>
		<dc:creator>Matthijs Kooijman</dc:creator>
		<pubDate>Wed, 23 Feb 2011 17:17:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.ultramegatech.com/blog/?p=528#comment-1759</guid>
		<description>Woops, never mind the final remark in my previous comment: Adding children to the DomDocument object seems to work, but actually adds the head and body tags _after_ the html object, not inside.

Anyway, I just noticed that DomDocument has a &quot;documentElement&quot; property, that does actually contain the HTML element. So the code would be:

$html = $document-&gt;documentElement;
$html-&gt;appendChild($head);
$html-&gt;appendChild($body);</description>
		<content:encoded><![CDATA[<p>Woops, never mind the final remark in my previous comment: Adding children to the DomDocument object seems to work, but actually adds the head and body tags _after_ the html object, not inside.</p>
<p>Anyway, I just noticed that DomDocument has a &#8220;documentElement&#8221; property, that does actually contain the HTML element. So the code would be:</p>
<p>$html = $document-&gt;documentElement;<br />
$html-&gt;appendChild($head);<br />
$html-&gt;appendChild($body);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matthijs Kooijman</title>
		<link>http://www.ultramegatech.com/2009/07/generating-xhtml-documents-using-domdocument-in-php/comment-page-1/#comment-1757</link>
		<dc:creator>Matthijs Kooijman</dc:creator>
		<pubDate>Wed, 23 Feb 2011 12:21:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.ultramegatech.com/blog/?p=528#comment-1757</guid>
		<description>Hi Steve,

good to see I&#039;m not the only one trying this cool stuff :-)

Anyway, I had some problems with your example, running on PHP 5.3 with the error reporting cranked all the way up:

Non-static method DOMImplementation::createDocumentType() should not be called statically, assuming $this from incompatible context

Seems like the DomImplementation methods aren&#039;t static methods, so you&#039;ll need to create an instance first. This snippet works for me:

                // Create document
                $impl = new DOMImplementation();
                $doctype = $impl-&gt;createDocumentType(&#039;html&#039;,
                                  &#039;-//W3C//DTD XHTML 1.1//EN&#039;,
                                  &#039;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&#039;);
                $document = $impl-&gt;createDocument(&#039;http://www.w3.org/1999/xhtml&#039;,
                                   &#039;html&#039;, $doctype);

Also, I&#039;ve found that there&#039;s an easy way to access the root &quot;html&quot; element: Just use the document itself. Since DOMDocument is a subclass of DOMNode, you can just add elements to it direclty:

    $document-&gt;appendChild($head);
    $document-&gt;appendChild($body);</description>
		<content:encoded><![CDATA[<p>Hi Steve,</p>
<p>good to see I&#8217;m not the only one trying this cool stuff <img src='http://www.ultramegatech.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Anyway, I had some problems with your example, running on PHP 5.3 with the error reporting cranked all the way up:</p>
<p>Non-static method DOMImplementation::createDocumentType() should not be called statically, assuming $this from incompatible context</p>
<p>Seems like the DomImplementation methods aren&#8217;t static methods, so you&#8217;ll need to create an instance first. This snippet works for me:</p>
<p>                // Create document<br />
                $impl = new DOMImplementation();<br />
                $doctype = $impl-&gt;createDocumentType(&#8216;html&#8217;,<br />
                                  &#8216;-//W3C//DTD XHTML 1.1//EN&#8217;,<br />
                                  &#8216;<a href="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" rel="nofollow">http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd</a>&#8216;);<br />
                $document = $impl-&gt;createDocument(&#8216;<a href="http://www.w3.org/1999/xhtml&#039;" rel="nofollow">http://www.w3.org/1999/xhtml&#039;</a>,<br />
                                   &#8216;html&#8217;, $doctype);</p>
<p>Also, I&#8217;ve found that there&#8217;s an easy way to access the root &#8220;html&#8221; element: Just use the document itself. Since DOMDocument is a subclass of DOMNode, you can just add elements to it direclty:</p>
<p>    $document-&gt;appendChild($head);<br />
    $document-&gt;appendChild($body);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://www.ultramegatech.com/2009/07/generating-xhtml-documents-using-domdocument-in-php/comment-page-1/#comment-1197</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Mon, 12 Apr 2010 18:07:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.ultramegatech.com/blog/?p=528#comment-1197</guid>
		<description>When you want to create an empty textarea, you just need to set its contents to an empty string. &lt;code&gt;$textarea = $document-&gt;createElement(&#039;textarea&#039;, &#039;&#039;);&lt;/code&gt; should produce the correct results.

Edit: Looks like we posted at the same time. What I posted is basically a shortcut to adding a text node.</description>
		<content:encoded><![CDATA[<p>When you want to create an empty textarea, you just need to set its contents to an empty string. <code>$textarea = $document->createElement('textarea', '');</code> should produce the correct results.</p>
<p>Edit: Looks like we posted at the same time. What I posted is basically a shortcut to adding a text node.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Miles</title>
		<link>http://www.ultramegatech.com/2009/07/generating-xhtml-documents-using-domdocument-in-php/comment-page-1/#comment-1196</link>
		<dc:creator>David Miles</dc:creator>
		<pubDate>Mon, 12 Apr 2010 18:00:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.ultramegatech.com/blog/?p=528#comment-1196</guid>
		<description>I spoke too soon ...
After taking another look at it and looking at how the form element had proper tags, I had an idea and it worked.  Here&#039;s what I did:
$textarea = $document-&gt;createElement(&#039;textarea&#039;);
$textarea-&gt;setAttribute(&#039;cols&#039;, &#039;50&#039;);
$textarea-&gt;setAttribute(&#039;rows&#039;, &#039;5&#039;);
$textarea-&gt;setAttribute(&#039;name&#039;, &#039;comments&#039;);
$blank = $document-&gt;createTextNode(&#039;&#039;);
$textarea-&gt;appendChild($blank);

By adding a blank textnode to it, it made it create both tags.  Simple fix.

Anyways, thanks again!</description>
		<content:encoded><![CDATA[<p>I spoke too soon &#8230;<br />
After taking another look at it and looking at how the form element had proper tags, I had an idea and it worked.  Here&#8217;s what I did:<br />
$textarea = $document-&gt;createElement(&#8216;textarea&#8217;);<br />
$textarea-&gt;setAttribute(&#8216;cols&#8217;, &#8217;50&#8242;);<br />
$textarea-&gt;setAttribute(&#8216;rows&#8217;, &#8217;5&#8242;);<br />
$textarea-&gt;setAttribute(&#8216;name&#8217;, &#8216;comments&#8217;);<br />
$blank = $document-&gt;createTextNode(&#8221;);<br />
$textarea-&gt;appendChild($blank);</p>
<p>By adding a blank textnode to it, it made it create both tags.  Simple fix.</p>
<p>Anyways, thanks again!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Miles</title>
		<link>http://www.ultramegatech.com/2009/07/generating-xhtml-documents-using-domdocument-in-php/comment-page-1/#comment-1195</link>
		<dc:creator>David Miles</dc:creator>
		<pubDate>Mon, 12 Apr 2010 17:51:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.ultramegatech.com/blog/?p=528#comment-1195</guid>
		<description>Hey Steve,
I want to first thank you for the great example here!  Documentation for DOMDocument is scarce and it&#039;s really hard to find any conclusive articles on generating XHTML with it, so your article was very useful.
I will note that the static calls to createDocument() and createElement() will trigger a Strict warning in PHP 5.3 since they aren&#039;t static methods, but that&#039;s an easy fix.

The problem I&#039;m having is when generating some form field types, mainly the textarea.  textarea fields must have a closing tag &quot;&quot; and cannot be closed like some of the others.  Unfortunately, it doesn&#039;t seem saveXML() realizes this and therefore creates incorrect textarea tags.  I haven&#039;t tried any of the others, so I&#039;m not sure, but &quot;input&quot; fields work fine and so does &quot;form&quot;.

Do you have any ideas on this?
Thanks.</description>
		<content:encoded><![CDATA[<p>Hey Steve,<br />
I want to first thank you for the great example here!  Documentation for DOMDocument is scarce and it&#8217;s really hard to find any conclusive articles on generating XHTML with it, so your article was very useful.<br />
I will note that the static calls to createDocument() and createElement() will trigger a Strict warning in PHP 5.3 since they aren&#8217;t static methods, but that&#8217;s an easy fix.</p>
<p>The problem I&#8217;m having is when generating some form field types, mainly the textarea.  textarea fields must have a closing tag &#8220;&#8221; and cannot be closed like some of the others.  Unfortunately, it doesn&#8217;t seem saveXML() realizes this and therefore creates incorrect textarea tags.  I haven&#8217;t tried any of the others, so I&#8217;m not sure, but &#8220;input&#8221; fields work fine and so does &#8220;form&#8221;.</p>
<p>Do you have any ideas on this?<br />
Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Modifying Templates Using DOMDocument In PHP &#124; UltraMega</title>
		<link>http://www.ultramegatech.com/2009/07/generating-xhtml-documents-using-domdocument-in-php/comment-page-1/#comment-79</link>
		<dc:creator>Modifying Templates Using DOMDocument In PHP &#124; UltraMega</dc:creator>
		<pubDate>Tue, 21 Jul 2009 17:20:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.ultramegatech.com/blog/?p=528#comment-79</guid>
		<description>[...] &#171; Generating (X)HTML Documents Using DOMDocument In PHP [...]</description>
		<content:encoded><![CDATA[<p>[...] &laquo; Generating (X)HTML Documents Using DOMDocument In PHP [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

