[PHPwestoz] Generating XML, for DOM work in JS
Timothy White
weirdit at gmail.com
Wed Mar 15 06:59:01 UTC 2006
I know about JSON, and for what I'm doing, think it's over kill... I'm
sure XML is overkill as well.
What is the 'right' way to do this, without using innerHTML? On the JS
side, I have managed to create DOM nodes, and append them to the
childnodes of a div, which is basically what innerHTML is doing, and
what I want done. But of course, I then have to create node for each
piece of formatting. The actually data coming from the PHP side can
need to be displayed in a few format's, but always appended to a div.
Hence I was hoping to put the grunt of the formatting on the
ServerSide, so the client just had to append a few nodes.
Hopefully someone on here knows the 'correct' alternative to using
innerHTMl (or even just another way).
Why do I not want to use innerHTMl? Because I want to TRY other
methods, and see how easy they are to use, and if they give us more
power than justs appending HTML.
Thanks
Tim
On 14/03/06, Samuel Cochran <sj26 at sj26.com> wrote:
> 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
>
> _______________________________________________
> PHPwestoz mailing list
> PHPwestoz at lists.linux.org.au
> http://lists.linux.org.au/listinfo/phpwestoz
>
--
Linux Counter user #273956
More information about the PHPwestoz
mailing list