Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.javascript
Then xmlns attribute in the XHTML DOM
ram
6/7/2016 2:04:00 AM
When no specific browser is targeted, just an implementation
of ECMAScript with the ECMAScript language bindings for DOM4,
and one wants to insert a span into the XHTML document
»this.document«, one might try this:
span = document.createElement( 'span' );
span.setAttribute( "xmlns", "
http://www.w3.org/1999/x...
);
document.getElementById( "example" ).appendChild( span );
, or
span = document.createElementNS( "
http://www.w3.org/1999/x...
, "span" );
document.getElementById( "example" ).appendChild( span )
, or even just
span = document.createElement( 'span' );
document.getElementById( "example" ).appendChild( span )
. Which of these three approaches is correct?
Especially, I'd like to know whether the last one, the one
that does no mention »w3.org«, already is correct.)
3 Answers
Osmo Saarikumpu
6/7/2016 11:46:00 AM
0
On 07/06/2016 05:04, Stefan Ram wrote:
> When no specific browser is targeted, just an implementation
> of ECMAScript with the ECMAScript language bindings for DOM4,
> and one wants to insert a span into the XHTML document
> »this.document«, one might try this:
>
> span = document.createElement( 'span' );
> span.setAttribute( "xmlns", "
http://www.w3.org/1999/x...
);
The span element does not have a xlmns attribute, only the document
element (html) has it.
> Especially, I'd like to know whether the last one, the one
> that does no mention »w3.org«, already is correct.)
Yes, it's the only correct one, assuming that your document has the html
element with the required xmlns attribute set.
--
Best wishes, Osmo
ram
6/7/2016 12:23:00 PM
0
Osmo Saarikumpu <osmo@weppipakki.com> writes:
>On 07/06/2016 05:04, Stefan Ram wrote:
>>When no specific browser is targeted, just an implementation
>>of ECMAScript with the ECMAScript language bindings for DOM4,
>>and one wants to insert a span into the XHTML document
>>»this.document«, one might try this:
>>span = document.createElement( 'span' );
>>span.setAttribute( "xmlns", "
http://www.w3.org/1999/x...
);
>The span element does not have a xlmns attribute, only the document
>element (html) has it.
I have observed this:
One can load the document from the URI
http://userpage.fu-berlin.de/~ram/pub/xhtml_jf47h...
in Firefox (it should delivered with
»application/xhtml+xml«) and then type
this.document.getElementById( "Zustand" ).outerHTML
into the console, which will make Firefox print
"<span xmlns="
http://www.w3.org/1999/x...
id="Zustand">(unbekannt)</span>"
. Now, one might ask:
What string do I have to assign to
»this.document.getElementById( "Zustand" ).outerHTML«
if I want nothing to be changed?
The obvious answer would as in the assignment
this.document.getElementById( "Zustand" ).outerHTML =
this.document.getElementById( "Zustand" ).outerHTML;
But given that
»this.document.getElementById( "Zustand").outerHTML«
is
»"<span xmlns="
http://www.w3.org/1999/x...
id="Zustand">(unbekannt)</span>"«,
this would be the same as the assignment
this.document.getElementById( "Zustand" ).outerHTML =
"<span xmlns="
http://www.w3.org/1999/x...
id="Zustand">(unbekannt)</span>"
. That's why I asked.
ram
6/7/2016 12:32:00 PM
0
ram@zedat.fu-berlin.de (Stefan Ram) writes:
>One can load the document from the URI
>
http://userpage.fu-berlin.de/~ram/pub/xhtml_jf47h...
>in Firefox (it should delivered with
>»application/xhtml+xml«) and then type
To make this clear. The source code of the document is:
<!DOCTYPE HTML><html xmlns="
http://www.w3.org/1999/x...
lang="de" xml:lang="de">
<head><meta charset="UTF-8" /><title>Hallo</title><style type="text/css">
</style></head><body>
<h1>Vornamen</h1>
<ul id="erste">
<li class="m a" id="Anton">Anton</li>
<li class="w b" id="Berta">Berta</li></ul>
<ul id="zweite">
<li class="c m" id="Cäsar">Cäsar</li>
<li class="d e w" id="Dora">Dora</li></ul>
<p>Es ist zur Zeit <span id="Zustand">(unbekannt)</span>.</p>
<pre><code><script type="application/javascript;version=1.8">/*<![CDATA[*/
/*]]>*/</script></code></pre></body></html>
. So, when Firefox is printing the outer HTML of the span as
"<span xmlns="
http://www.w3.org/1999/x...
id="Zustand">(unbekannt)</span>"
it has /added/ the xmlns attribute which is not written in
the page source.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Then xmlns attribute in the XHTML DOM
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password