469,352 Members | 1,694 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

innerXML

Why isn't there a way in standard DOM to access all XML of a node?
(Similar to what outerHTML and innerHTML can do on Firefox or Internet
Explorer when accessing HTML.)
Or am I missing something?

--
Google Blogoscoped
http://blog.outer-court.com
Jul 20 '05 #1
6 7434


Philipp Lenssen wrote:
Why isn't there a way in standard DOM to access all XML of a node?
(Similar to what outerHTML and innerHTML can do on Firefox or Internet
Explorer when accessing HTML.)
Or am I missing something?


Well outerXml, that is the serialization of the node itself can
certainly be achieved with W3C DOM Level 3 Load and Save e.g. with Opera
7.60 Preview you can do

function getOuterXml (node) {
if (node.ownerDocument && node.ownerDocument.implementation &&
document.implementation.createLSSerializer &&
(serializer =
node.ownerDocument.implementation.createLSSerializ er()))
{
return serializer.writeToString(node);
}
}

getOuterXml(someNode)

I think Java 1.5 (also named Java 5.0) also implements DOM Level 3 Load
and Save so there you are also able to serialize a node with standard
DOM ways:
http://java.sun.com/j2se/1.5.0/docs/api/index.html

And innerXml only requires you to serialize all child nodes and
concatenate the results.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
Martin Honnen wrote:
And innerXml only requires you to serialize all child nodes and
concatenate the results.


I did that once in Visual Basic. Of course it takes some efforts, and I
wonder, really wonder -- and I'm not the only one, my colleagues wonder
as well :) -- why this is not in the basic DOM (innerXML and outerXML).

I'm using PHP5. Any code samples are very welcome. Both Outer and
InnerXML would be great.

--
Google Blogoscoped
http://blog.outer-court.com
Jul 20 '05 #3


Philipp Lenssen wrote:

I'm using PHP5. Any code samples are very welcome. Both Outer and
InnerXML would be great.


According to the docs all you need for "OuterXml" is
xmlDocument->saveXML(node)
as documented here
http://www.php.net/manual/en/functio...nt-savexml.php
For "InnerXml" you would then need to concatenate the OuterXml of all
child nodes:
function getInnerXml ($node) {
$innerXml = '';
$xmlDoc = $node->ownerDocument;
for ($i = 0; $i < $node->childNodes->length; $i++) {
$innerXml .= $xmlDoc->saveXML($node->childNodes[$i]);
}
return $innerXml;
}

All untested as I currently here do not have PHP 5 installed.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #4
Martin Honnen wrote:


Philipp Lenssen wrote:

I'm using PHP5. Any code samples are very welcome. Both Outer and
InnerXML would be great.


According to the docs all you need for "OuterXml" is
xmlDocument->saveXML(node)
as documented here
http://www.php.net/manual/en/functio...nt-savexml.php


Thanks a lot Martin, that'll do! I will try "saveXML".

--
Google Blogoscoped
http://blog.outer-court.com
Jul 20 '05 #5
Philipp Lenssen wrote:
Martin Honnen wrote:


Philipp Lenssen wrote:

I'm using PHP5. Any code samples are very welcome. Both Outer and
InnerXML would be great.


According to the docs all you need for "OuterXml" is
xmlDocument->saveXML(node)
as documented here
http://www.php.net/manual/en/functio...nt-savexml.php


Thanks a lot Martin, that'll do! I will try "saveXML".


Works like a charm.
Jul 20 '05 #6


Martin Honnen wrote:

For "InnerXml" you would then need to concatenate the OuterXml of all
child nodes:
function getInnerXml ($node) {
$innerXml = '';
$xmlDoc = $node->ownerDocument;
for ($i = 0; $i < $node->childNodes->length; $i++) {
$innerXml .= $xmlDoc->saveXML($node->childNodes[$i]);


The square bracket access to childNodes doesn't work so you need

function getInnerXml ($node) {
$innerXml = '';
$xmlDoc = $node->ownerDocument;
for ($i = 0; $i < $node->childNodes->length; $i++) {
$innerXml .= $xmlDoc->saveXML($node->childNodes->item($i));
}
return $innerXml;
}

but then it works fine.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Martin Madreza | last post: by
3 posts views Thread by Bas Jaburg | last post: by
1 post views Thread by ALI-R | last post: by
2 posts views Thread by =?Utf-8?B?c2VlbWE=?= | last post: by
4 posts views Thread by =?Utf-8?B?TWFyaw==?= | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.