473,378 Members | 1,411 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 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 7594


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 to the XmlNode InnerXml property ...
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 leaks cpu-resources. A trivial example showing...
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 want the special characters escaped, but I want to...
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: things.xml <things> <people> <name>Peter</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" ?> <table id="klasse" records="4792"> <record...
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 a way to format the innertext in a tooltip. ...
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 im searching for is "item001" then I want the...
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 that XmlDocument.Load() or .LoadXml() will...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.