472,353 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

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 7519


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Martin Madreza | last post by:
hello, i despair on one simple problem (maybe it's to simple???) I have the string txt = "hallo</hmm>" or txt = "am&24" and want to pass it...
3
by: Henrik K | last post by:
Selecting element nodes from a xmlDataDocument using the childNodes collection or by using selectSingleNode and then reading innerXml or outerXml...
2
by: kben | last post by:
I'm trying to get some text into an XMLElement that may or may not contain markup, and it may or may not contain characters that need escaping. I...
1
by: Peter Nofelt | last post by:
Hey All, I'm running into this issue with parsing through an xml document by tag name. Below is an example xml document: File Name:...
3
by: Bas Jaburg | last post by:
I'm creating a Windows App in C#(Smart Client)that calls a webservice. The webservice returns this: <?xml version="1.0" encoding="utf-8" ?>...
1
by: ALI-R | last post by:
I am showing the InnerXml of a node (in a treeView Control) in a tooltip ,but it is not formatted well ,all the elements after each other ,is there...
15
by: janhm | last post by:
Hello. I need to loop through a xml file finding a specific innerxml text and then ad the content to a treeview. For example. If the innerxml...
2
by: =?Utf-8?B?c2VlbWE=?= | last post by:
What is the differnce between outerXML and innerXML.
4
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi... I just noticed something that seems counter-intuitive to me. By default an XmlDocument is set with PreserveWhitespace=false. This means...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.