Re: [PHP-XML-DEV] DomDocument, insert HTML Element

[email protected] (Martel Valgoerad) Fri, 12 Nov 2004 13:29:06 +0100
Newsgroups php.xml.dev
Message-ID <[email protected]>
Rob Richards wrote:

>> Is there any place where I can find the documentation for DocumentFragment
>> or even attributes of DomDocument like resolveExternals or 
>> substituteEntities? 
> You can check some old outdated docs - these are pre manual docs so dont
> trust everything you read - at http://www.ctindustries.net/dom/.
> Here you'll find the properties for the objects (Havent figured out how to
> document the properties correctly in the manual).

Thanks.

>> I'm using XML + XSLT as a templating engine. In this particular case I'm
>> dealing with form user input which accepts HTML (and then is stored in a
>> database). What approach would you recommend? Of course, if it's not too
>> bold to ask given this thread is highly off-topic.
> You can always store the user submitted data in a CDATA node - this pretty
> much is free form text.

Oh my, I haven't thought about this. I love you, Rob. In case someone would
look for a similar solution I'll leave some pointers.

After using CDATASection I ended up with:

<?xml version="1.0" encoding="UTF-8"?>
<root><article id="2335"><body><![CDATA[Some kind of <a
href="http://cos.com">HTML</a>]]></body></article></root>

As you can clearly see, the XML is free of encoded entities but the result
after the XSL transformation was still escaped. In order to get it to work
you have to disable escaping in xsl template and... voila:

<xsl:template match="article">
 <div class="article">
 <p style="text-align: justify;">
  <xsl:value-of select="body" disable-output-escaping="yes" />
 </p>
 </div>
</xsl:template>

> If you need the submitted data to parse correctly into a tree (like using
> the appendXML method), for PHP 5.0.x you can try the following hack:

Thanks again :)

-- 
Martel Valgoerad   (a.k.a. Michal Minicki) | "Courage is resistance to fear,
alea.iacta.est | Martel --> [email protected] | mastery of fear - not absence
Web Page:                http://www.aie.pl | of fear." M. Twain