Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

change dynamic contentType/Namespace of a document?

8 views
Skip to first unread message

Thomas

unread,
Nov 29, 2006, 2:00:32 PM11/29/06
to
Hi,

i have a HTML file in my Firefox and its contentType is "html/text". Now
i try to change this contentType to XHTML ("application/xhtml+xml").
document.contentType or document.namespaceURI can't be set (readonly).
I try to make a new HTML node with:

var new_html =
current_doc().createElementNS("http://www.w3.org/1999/xhtml", "html");

And filled it with the old HTML stuff, but if i try to replace the
original HTML-node i get an empty document.

Has someone an idea or has someone already done this?

greeting Thomas

Nickolay Ponomarev

unread,
Dec 3, 2006, 7:21:43 PM12/3/06
to Thomas, dev-ext...@lists.mozilla.org
What are you trying to accomplish?

Nickolay

Thomas

unread,
Dec 4, 2006, 4:51:56 AM12/4/06
to
I have a HTML-File (HTML 4.01) with some MathML-Objects. Now, i try to
weave it in the HTML File that the original page doen't have <object>
tags anymore. That work fine, i detect if the <object> is MathML
Namespace and i create a <math> tag instead of the object.
The problem is, that the MathML code wouldn't be presented correctly. I
have created the <math> tag with the
rigth namespace
(document.createElementNS('http://www.w3.org...','math')), but the
presentation is not correct. If i use <math> tags inside a HTML File
with the extension *.xhtml, the MathML code looks correct (the
contentType is "application/html+xml"). Therefore i tryed to change the
contentType of a document.

I have created the new HTML, HEAD, BODY nodes with
document.createElementNS(NS_FOR_XHTML, 'html') and attached the old
nodes with cloneNode(true), but the representation isn't correctly and
if i ask for the contentType (document.contentType) it is still "html/text".

Thomas

Nickolay Ponomarev

unread,
Dec 4, 2006, 9:32:53 AM12/4/06
to Thomas, dev-ext...@lists.mozilla.org
On 12/4/06, Thomas <muell_...@gmx.net> wrote:
> Nickolay Ponomarev wrote:
> > On 11/29/06, Thomas <muell_...@gmx.net> wrote:
> >> Has someone an idea or has someone already done this?
> >>
> > What are you trying to accomplish?
> I have a HTML-File (HTML 4.01) with some MathML-Objects. Now, i try to
> weave it in the HTML File that the original page doen't have <object>
> tags anymore. That work fine, i detect if the <object> is MathML
> Namespace and i create a <math> tag instead of the object.
> The problem is, that the MathML code wouldn't be presented correctly. I
> have created the <math> tag with the
> rigth namespace
> (document.createElementNS('http://www.w3.org...','math')), but the
> presentation is not correct. If i use <math> tags inside a HTML File
> with the extension *.xhtml, the MathML code looks correct (the
> contentType is "application/html+xml"). Therefore i tryed to change the
> contentType of a document.
>
The content type determines what parser is used to parse the document
and what kind of document is created. Changing this after the document
is loaded is not possible.

I'm not sure I understand your problem. I think you're trying to embed
MathML elements directly in a text/html document, right? Since the
HTML parser doesn't know anything about MathML or namespaces, it can't
generate the correct DOM for your MathML elements.

It looks like you tried to create and append the needed MathML
elements manually, but it's not clear what exactly did you try.
Ideally this should work, but I'm not sure if MathML has any bugs on
this.

Can you show a testcase demonstrating what you are trying to do?

> I have created the new HTML, HEAD, BODY nodes with
> document.createElementNS(NS_FOR_XHTML, 'html') and attached the old
> nodes with cloneNode(true), but the representation isn't correctly and
> if i ask for the contentType (document.contentType) it is still "html/text".
>

I'm not sure why you decided to try this.

Nickolay


> Thomas
> _______________________________________________
> dev-extensions mailing list
> dev-ext...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-extensions
>

Thomas

unread,
Dec 4, 2006, 12:07:41 PM12/4/06
to
Nickolay Ponomarev wrote:
> The content type determines what parser is used to parse the document
> and what kind of document is created. Changing this after the document
> is loaded is not possible.
Is it possible to change some things (like a service) and reload the
page and the parser will be represent the content in the way i want? I
haven't found something for it.

> I'm not sure I understand your problem. I think you're trying to embed
> MathML elements directly in a text/html document, right? Since the
> HTML parser doesn't know anything about MathML or namespaces, it can't
> generate the correct DOM for your MathML elements.

Yes, your absolutly right!

> It looks like you tried to create and append the needed MathML
> elements manually, but it's not clear what exactly did you try.
> Ideally this should work, but I'm not sure if MathML has any bugs on
> this.

The aim is, that i can select nodes and generate XPaths of some MathML
nodes. If they are embeded as <object> i can only select/seee the
object-tag in the DOM, but not the MathML stuff.

> Can you show a testcase demonstrating what you are trying to do?

Hmm, i think its too much to post all that. But i have uploaded my
testpages:
http://credes.psiegmund.de/ff/mathml.xhtml
this is the XHTML webpage with the <math> tag inside. that is my aim to
generate. It shows the MathML stuff correctly.

http://credes.psiegmund.de/ff/mathml_object.html
this is the source page. The MathML-object will be offline displayed
correctly. I get some error during online display, don't know why. You
can try to download the page and the MathML objectfile:
http://credes.psiegmund.de/ff/bsp_formel_klein.mml

Nickolay Ponomarev

unread,
Dec 4, 2006, 12:51:59 PM12/4/06
to Thomas, dev-ext...@lists.mozilla.org
On 12/4/06, Thomas <muell_...@gmx.net> wrote:
> Nickolay Ponomarev wrote:
> > The content type determines what parser is used to parse the document
> > and what kind of document is created. Changing this after the document
> > is loaded is not possible.
> Is it possible to change some things (like a service) and reload the
> page and the parser will be represent the content in the way i want? I
> haven't found something for it.
>
So.. Who controls the web page? Is it your own page or are you
creating an extension which should work on any page with MathML?

(My understanding is that) It is not possible to have MathML in
text/html tag soup markup. If you have XHTML with embedded MathML you
should send it with the appropriate content type. If it's not
well-formed XHTML with proper namespaces etc, the XHTML parser won't
be able to cope with the document anyway.

> > I'm not sure I understand your problem. I think you're trying to embed
> > MathML elements directly in a text/html document, right? Since the
> > HTML parser doesn't know anything about MathML or namespaces, it can't
> > generate the correct DOM for your MathML elements.
> Yes, your absolutly right!
>
> > It looks like you tried to create and append the needed MathML
> > elements manually, but it's not clear what exactly did you try.
> > Ideally this should work, but I'm not sure if MathML has any bugs on
> > this.
> The aim is, that i can select nodes and generate XPaths of some MathML
> nodes. If they are embeded as <object> i can only select/seee the
> object-tag in the DOM, but not the MathML stuff.
>

That's expected, but you still don't tell enough information. Are
text/html pages with <object> elements something you -have- to work
with or is it something you control? Why do you need to generate an
XPath expression (and not, say, two XPath expressions, one pointing to
the <object> element in the parent document and another pointing to
the MathML element in the inner document)? How is this related to
trying to build MathML content dynamically using createElementNS?

> > Can you show a testcase demonstrating what you are trying to do?
> Hmm, i think its too much to post all that. But i have uploaded my
> testpages:
> http://credes.psiegmund.de/ff/mathml.xhtml
> this is the XHTML webpage with the <math> tag inside. that is my aim to
> generate. It shows the MathML stuff correctly.
>
> http://credes.psiegmund.de/ff/mathml_object.html
> this is the source page. The MathML-object will be offline displayed
> correctly. I get some error during online display, don't know why. You
> can try to download the page and the MathML objectfile:
> http://credes.psiegmund.de/ff/bsp_formel_klein.mml

Your webserver serves the MathML file with an incorrect content type,
you should configure it properly.

Nickolay

Thomas

unread,
Dec 5, 2006, 4:29:20 AM12/5/06
to
Nickolay Ponomarev wrote:
> So.. Who controls the web page? Is it your own page or are you
> creating an extension which should work on any page with MathML?
Sorry for the raw informations :-)
The extension should work with every page in the web. My task is to let
the user comment some nodes. The user selects a (e.g. <p>) tag or any
other tag and writes some information. This information will be saved
and if the user visit the same webpage again, his commend should be
written on the page.
If the user visit a XHTML page, he can klick on every tag and on every
tag inside a MathML tag to select a node and the user can write some
informations.
If the user visits a HTML page with a MathML-object he can select a part
of the page and/or a part of the MathML object, but i don't get the
right XPath of this embed tags. (you still know this)

> That's expected, but you still don't tell enough information. Are
> text/html pages with <object> elements something you -have- to work
> with or is it something you control? Why do you need to generate an
> XPath expression (and not, say, two XPath expressions, one pointing to
> the <object> element in the parent document and another pointing to
> the MathML element in the inner document)? How is this related to
> trying to build MathML content dynamically using createElementNS?

To generate 2 XPaths is a good idea and i think this would work to get
the XPath. But if the user visits the webpage again, i can't resolve the
XPath and navigate inside the MathML object to select the right tag.
That is a problem of the DOM. I would walk throuh the DOM, like the
XPath says, to select the right tag.
The only solution i found, was to weave the MathML stuff inside the
webpage, but the represenation wouldn't be right (you still know).

Nickolay Ponomarev

unread,
Dec 5, 2006, 12:15:15 PM12/5/06
to Thomas, dev-ext...@lists.mozilla.org
On 12/5/06, Thomas <muell_...@gmx.net> wrote:
> Nickolay Ponomarev wrote:
> > That's expected, but you still don't tell enough information. Are
> > text/html pages with <object> elements something you -have- to work
> > with or is it something you control? Why do you need to generate an
> > XPath expression (and not, say, two XPath expressions, one pointing to
> > the <object> element in the parent document and another pointing to
> > the MathML element in the inner document)? How is this related to
> > trying to build MathML content dynamically using createElementNS?
> To generate 2 XPaths is a good idea and i think this would work to get
> the XPath. But if the user visits the webpage again, i can't resolve the
> XPath and navigate inside the MathML object to select the right tag.
> That is a problem of the DOM. I would walk throuh the DOM, like the
> XPath says, to select the right tag.
> The only solution i found, was to weave the MathML stuff inside the
> webpage, but the represenation wouldn't be right (you still know).

IMO, the right solution would be to store a separate XPath for each
subdocument (e.g. one in an <iframe> or in an <object>). Then when you
resolve such "compound" XPath expression, you resolve the first
expression in the sequence, take the resulting element's
contentDocument property, resolve the second expression in that
document, etc.

One of the reasons I wouldn't mess with page's DOM is that doing so
may break the scripts on the page.

Nickolay

Thomas

unread,
Dec 5, 2006, 12:48:38 PM12/5/06
to
Nickolay Ponomarev wrote:
> IMO, the right solution would be to store a separate XPath for each
> subdocument (e.g. one in an <iframe> or in an <object>). Then when you
> resolve such "compound" XPath expression, you resolve the first
> expression in the sequence, take the resulting element's
> contentDocument property, resolve the second expression in that
> document, etc.
Yes, thats the better way, but it doesn't work. I can walk DOM down to
the <object>, <embed> or <iframe> tag, but i can't go deeper. If i make:
var object_childs_array = anObject.childNodes
The object/embed/iframe tag has only one child and this is a textnode
with "you browser doesn't support MathML" or "your browser doen't
support iframes".
Do you know a way to walk down the nodes inside a <object>?

> One of the reasons I wouldn't mess with page's DOM is that doing so
> may break the scripts on the page.

Hmm, yes, thats a point. :-/ But its not a problem, because it doesn't
work with weaving the MathML stuff into the webpage.

Thomas

Nickolay Ponomarev

unread,
Dec 6, 2006, 3:01:26 AM12/6/06
to Thomas, dev-ext...@lists.mozilla.org
On 12/5/06, Thomas <muell_...@gmx.net> wrote:
> Nickolay Ponomarev wrote:
> > IMO, the right solution would be to store a separate XPath for each
> > subdocument (e.g. one in an <iframe> or in an <object>). Then when you
> > resolve such "compound" XPath expression, you resolve the first
> > expression in the sequence, take the resulting element's
> > contentDocument property, resolve the second expression in that
> > document, etc.
> Yes, thats the better way, but it doesn't work. I can walk DOM down to
> the <object>, <embed> or <iframe> tag, but i can't go deeper. If i make:
> var object_childs_array = anObject.childNodes
> The object/embed/iframe tag has only one child and this is a textnode
> with "you browser doesn't support MathML" or "your browser doen't
> support iframes".
> Do you know a way to walk down the nodes inside a <object>?
>

I wrote earlier "take the resulting element's [iframe/object's]
contentDocument property". Is that not clear enough?

Nickolay

Thomas

unread,
Dec 6, 2006, 5:38:39 AM12/6/06
to
Damn, your right. This works fine!
Why isn't this property explained
(http://developer.mozilla.org/en/docs/DOM:element)?
Thanks a lot. This will work.

Thomas

Thomas

unread,
Dec 6, 2006, 3:03:35 PM12/6/06
to
Thomas wrote:

> Nickolay Ponomarev wrote:
>> I wrote earlier "take the resulting element's [iframe/object's]
>> contentDocument property". Is that not clear enough?
> Damn, your right. This works fine!
Hmm, it doen't work. I can go down, of course. But if i'm inside the
object and have a node and try to walk up, it doen't work.
I can go to the highest node inside the object (in MathML this is
<math>) and if i make parentNode, i became a "[object XMLDocument]". If
i take the parent of this (the parent of xml-document must be the
object-node), i get NULL. Therefore it isn't possible to generate the XPath.

Thomas

Neil

unread,
Dec 6, 2006, 6:34:48 PM12/6/06
to
Thomas wrote:

> Thomas wrote:
>
>> Nickolay Ponomarev wrote:
>>
>>> I wrote earlier "take the resulting element's [iframe/object's]
>>> contentDocument property". Is that not clear enough?
>>
>> Damn, your right. This works fine!
>
> Hmm, it doen't work. I can go down, of course. But if i'm inside the
> object and have a node and try to walk up, it doen't work.

I think what might work is docNode.defaultView.frameElement

--
Warning: May contain traces of nuts.

Thomas

unread,
Dec 7, 2006, 5:51:32 AM12/7/06
to
Neil wrote:

> Thomas wrote:
>> Hmm, it doen't work. I can go down, of course. But if i'm inside the
>> object and have a node and try to walk up, it doen't work.
>
> I think what might work is docNode.defaultView.frameElement

IT WORKS! Thanks a lot! Why are these properties doen't explained? :-/

Nickolay Ponomarev

unread,
Dec 7, 2006, 5:55:09 AM12/7/06
to Thomas, dev-ext...@lists.mozilla.org

Where and how should they have been explained to make it easier to you
to find the needed information? You can tell us how we can improve the
docs or just do it yourself - either way it will be appreciated.

Nickolay

0 new messages