innerHTML/outerHTML properties and preservation of literal text

D

Dave

Hello,

I'm working with DHTML in a web application I'm building and I've run
into a problem that I'm not sure is resolvable.

I've been using the innerHTML and outerHTML properties of elements in
my web pages and grabbing the desired elements by assigning an ID and
then using the document.getElementById() method to retrieve an object
reference to the desired element. This is not a problem and works in
all the 5+ versions of IE I've tested (on Windows and Mac platforms).

The problem is that the string returned from the innerHTML or
outerHTML property does not preserve the quotes located in the text in
the actual document. So the following element:

<XML ID="xml_test">
<nodes>
<node myname="some_name">1</node>
<node myname="some_name">2</node>
</nodes>
</XML>

if shown with, say, alert(document.getElementById("xml_test").outerHTML)
would create a popup containing:

<XML ID=xml_test>
<nodes>
<node myname=some_name>1</node>
<node myname=some_name>2</node>
</nodes>
</XML>

The reason this is problematic is that there are times I wish to use
the element text literally, and the missing quotes pretty much screws
the javascript functions I've already written.

If anyone knows how to code around this issue or if there is a fix for
it that can be applied to the browser so it will show literal text
from these properties, please post an answer in reply to one of these
groups. Sorry for the cross-posting but I really need to figure out a
way around this and don't know which group is most appropriate.

Thanks in advance for your help.

Regards,
Dave Spaar
 
R

Randy Webb

Dave said:
Hello,

I'm working with DHTML in a web application I'm building and I've run
into a problem that I'm not sure is resolvable.

I've been using the innerHTML and outerHTML properties of elements in
my web pages and grabbing the desired elements by assigning an ID and
then using the document.getElementById() method to retrieve an object
reference to the desired element. This is not a problem and works in
all the 5+ versions of IE I've tested (on Windows and Mac platforms).

The problem is that the string returned from the innerHTML or
outerHTML property does not preserve the quotes located in the text in
the actual document. So the following element:

<XML ID="xml_test">
<nodes>
<node myname="some_name">1</node>
<node myname="some_name">2</node>
</nodes>
</XML>

if shown with, say, alert(document.getElementById("xml_test").outerHTML)
would create a popup containing:

<XML ID=xml_test>
<nodes>
<node myname=some_name>1</node>
<node myname=some_name>2</node>
</nodes>
</XML>

The reason this is problematic is that there are times I wish to use
the element text literally, and the missing quotes pretty much screws
the javascript functions I've already written.

If anyone knows how to code around this issue or if there is a fix for
it that can be applied to the browser so it will show literal text
from these properties, please post an answer in reply to one of these
groups. Sorry for the cross-posting but I really need to figure out a
way around this and don't know which group is most appropriate.

If you are needing the literal text, then you will have to read the file
itself, not the inner/outerHTML properties as those will return to you
"normalized" source that you are seeing. One possibility is the use of
the HTTPRequest Object to read the file, another is to use a Java Applet
to read the file. Both can be found in <URL:
http://www.jibbering.com/faq/#FAQ4_38 >
 
H

Howdy

Dave,

e-mail me and I'll send you a .asp with some java code I wrote that
gives you on the page table column sorts with clickable column headers
and the java code maintains the text and cell formatting.

Phil

Hello,

I'm working with DHTML in a web application I'm building and I've run
into a problem that I'm not sure is resolvable.

I've been using the innerHTML and outerHTML properties of elements in
my web pages and grabbing the desired elements by assigning an ID and
then using the document.getElementById() method to retrieve an object
reference to the desired element. This is not a problem and works in
all the 5+ versions of IE I've tested (on Windows and Mac platforms).

The problem is that the string returned from the innerHTML or
outerHTML property does not preserve the quotes located in the text in
the actual document. So the following element:

<XML ID="xml_test">
<nodes>
<node myname="some_name">1</node>
<node myname="some_name">2</node>
</nodes>
</XML>

if shown with, say, alert(document.getElementById("xml_test").outerHTML)
would create a popup containing:

<XML ID=xml_test>
<nodes>
<node myname=some_name>1</node>
<node myname=some_name>2</node>
</nodes>
</XML>

The reason this is problematic is that there are times I wish to use
the element text literally, and the missing quotes pretty much screws
the javascript functions I've already written.

If anyone knows how to code around this issue or if there is a fix for
it that can be applied to the browser so it will show literal text
from these properties, please post an answer in reply to one of these
groups. Sorry for the cross-posting but I really need to figure out a
way around this and don't know which group is most appropriate.

Thanks in advance for your help.

Regards,
Dave Spaar

===============================================
p h i l p a t s e r v i a n c e d o t c o m
===============================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top