[PHPwestoz] Generating XML, for DOM work in JS

Samuel Cochran sj26 at sj26.com
Tue Mar 14 23:42:02 UTC 2006


Why not just write:

<p>This is the test text<br /></p>

Or whatever you have to? Use javascript to tack this onto the end of
innerHTML of wherever you want it... You conserve a lot of proccesing
power on the server-side for maybe a little bit more grunty javascript
(although still negligable).

If you're wanting to communicate actual data then JSON is the best
option as it can be natively interpreted by the browser. There's a
really shiny PEAR class:

http://pear.php.net/pepr/pepr-proposal-show.php?id=198

.. or you can use the native C extension for speed:

http://www.aurore.net/projects/php-json/

I actually prefer using JSON to send data only and get the client-side
JS to present it.

-- Sam

On 3/14/06, Timothy White <weirdo at tigris.org> wrote:
> I'm looking at generating XML via PHP, so that I can get it with a JS
> 'ajax' call, and then append a node from the XML DOM tree, into the
> Document DOM tree.
>
> Currently I'm trying to generate the XML with the following[1] but
> when I get the DOM Node, and Append it via JS to the XHTML doc, it
> doesn't appear to have the correct element types, instead of things
> like HTMLParagraphElement it's just a Element :(
>
> Any ideas?
>
> Thanks
>
> Tim
>
> [1]
> <?php
> header("Content-type: text/xml");
> $doc = domxml_new_doc("1.0");
> /* The following line does not appear to make a difference ether way */
> $doc->set_namespace('http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd');
>
> $root = $doc->create_element("P");
> $root = $doc->append_child($root);
> $br = $doc->create_element("BR");
> $text = $doc->create_text_node("This is the test text");
> $text = $root->append_child($text);
> $root->append_child($br);
> echo $doc->dump_mem();
> ?>
> --
> Linux Counter user #273956

--
Samuel Cochran
sj26 at sj26.com




More information about the PHPwestoz mailing list