XML Islands in Firefox

T

tomicmilan

I have this HTML:

<html>
<head>
<style type="text/css">
xml {display: none;}
</style>
<script language="JavaScript">
function test() {
alert(document.getElementById("zahtevek").innerHTML);
}
</script>
</head>
<body>
<div><xml id="zahtevek"><cd:Document xmlns:cd="http://
Document"><cd:Data Id="Data"/></cd:Document></xml></div>
<input type="button" name="Test" value="Test" onclick="test()">
</body>
</html>

Well, the problem is that innerHTML returns lower case XML
(cd:document instead of cd:Document...) and I need to preserve XML (it
shouldn't be modified in any way).

What should I do?
 
B

Bart Van der Donck

I have this HTML:

<html>
<head>
<style type="text/css">
xml {display: none;}
</style>
<script language="JavaScript">
function test() {
  alert(document.getElementById("zahtevek").innerHTML);}>
</script>
</head>
<body>
<div><xml id="zahtevek"><cd:Document xmlns:cd="http://
Document"><cd:Data  Id="Data"/></cd:Document></xml></div>
<input type="button" name="Test" value="Test" onclick="test()">
</body>
</html>

Well, the problem is that innerHTML returns lower case XML
(cd:document instead of cd:Document...) and I need to preserve XML (it
shouldn't be modified in any way).

You cannot trust innerHTML to return the correct XML. Please see:

http://www.w3schools.com/xml/xml_parser.asp

Hope this helps,
 
T

tomicmilan

Yes, I know I can not trust innerHTML. That is why I am asking for
help here. I have already seen the link you posted but it didn't
helped me.

With document.getElementById("zahtevek") I get a reference to <xml>
element but I don't know how to extract XML as a string from it. :
( That is the problem.
 
M

Martin Honnen

Yes, I know I can not trust innerHTML. That is why I am asking for
help here. I have already seen the link you posted but it didn't
helped me.

With document.getElementById("zahtevek") I get a reference to <xml>
element but I don't know how to extract XML as a string from it. :
( That is the problem.

Firefox does not support XML data islands in HTML documents. However you
can use XMLHttpRequest to load an XML document and access its DOM as
responseXML. That works for IE too.
 
B

Bart Van der Donck

Yes, I know I can not trust innerHTML. That is why I am asking for
help here. I have already seen the link you posted but it didn't
helped me.

With document.getElementById("zahtevek") I get a reference to <xml>
element but I don't know how to extract XML as a string from it. :
( That is the problem.

Maybe you could use <textarea> in stead of <div>:

<form method="get" action="#">
<textarea cols="60" rows="10" name="zahtevek">
<xml id="zahtevek">
<cd:Document xmlns:cd="http://Document">
<cd:Data Id="Data"/>
</cd:Document>
</xml>
</textarea>
<input type="button" name="Test" value="Test"
onclick="alert(document.forms[0].zahtevek.value);">
</form>

With CSS and onFocus="blur()" it looks identical as a div.
 
T

tomicmilan

Yes, I know I can not trust innerHTML. That is why I am asking for
help here. I have already seen the link you posted but it didn't
helped me.
With document.getElementById("zahtevek") I get a reference to <xml>
element but I don't know how to extract XML as a string from it. :
( That is the problem.

Maybe you could use <textarea> in stead of <div>:

<form method="get" action="#">
<textarea cols="60" rows="10" name="zahtevek">
<xml id="zahtevek">
<cd:Document xmlns:cd="http://Document">
<cd:Data Id="Data"/>
</cd:Document>
</xml>
</textarea>
<input type="button" name="Test" value="Test"
onclick="alert(document.forms[0].zahtevek.value);">
</form>

With CSS and onFocus="blur()" it looks identical as a div.

I have tried that today but it doesn't work for me. Special characters
(©ÐÈÆ®¹ðèæ¾) are not properly handled when placed into and taken from
an textarea. I will have to follow Martin's advice and use
XMLHttpRequest.
 
B

Bart Van der Donck

Bart Van der Donck wrote:
    <form method="get" action="#">
    <textarea cols="60" rows="10" name="zahtevek">
    <xml id="zahtevek">
     <cd:Document xmlns:cd="http://Document">
      <cd:Data Id="Data"/>
     </cd:Document>
    </xml>
    </textarea>
    <input type="button" name="Test" value="Test"
     onclick="alert(document.forms[0].zahtevek.value);">
    </form>

I have tried that today but it doesn't work for me. Special characters
(©ÐÈÆ®¹ðèæ¾) are not properly handled when placed intoand taken from
an textarea. I will have to follow Martin's advice and use
XMLHttpRequest.

If I'm receiving your encoding correctly, this looks like a two-byte
encoded UTF-8 string. The character set of the page + how it was saved
determine how it will be displayed. You appear to post from Slovenia,
so either you could use ISO-8859-2 (or one of the proprietary Central-
European code pages), or, preferably, UTF-8.

Two examples:

http://www.dotinternet.be/temp/1.htm (saved in UTF-8)
versus
http://www.dotinternet.be/temp/2.htm (not saved in UTF-8!)

My guess what you are seeing:
http://www.dotinternet.be/temp/3.htm

With this in mind, <textarea> should always return the right
characters.
 
T

The Magpie

I have this HTML:

<html> [snip] <xml id="zahtevek"><cd:Document xmlns:cd="http://

Well, the problem is that innerHTML returns lower case XML
(cd:document instead of cd:Document...) and I need to preserve XML (it
shouldn't be modified in any way).

What should I do?

Stop using XML Data Islands. They are a Microsoft feature and are not
supported on many other browsers - certainly not on Firefox.
 

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

Members online

No members online now.

Forum statistics

Threads
474,002
Messages
2,570,261
Members
46,858
Latest member
FlorrieTuf

Latest Threads

Top