importNode and root node name

Discussion in 'Javascript' started by Une Bévue, Apr 26, 2008.

  1. Une Bévue

    Une Bévue Guest

    at the page :
    <http://thoraval.yvon.free.fr/Fixed_layout/import_nodes.xhtml>
    when importing an svg document i have to do :
    document.importNode(
    req.responseXML.getElementsByTagName(req.parameters.root)[0],true))

    (lines 46/47)

    in case of SVG : req.parameters.root = 'svg'
    and 'math' in case of MathML


    there is no DOM method for getting the root node, enabling not to
    specify the root is svg|math ???

    or could i do that using DOM/XPath ?

    ie something like :
    req.responseXML.evaluate('/',document, nsResolver, XPathResult.ANY_TYPE,
    null);

    ???
    --
    Une Bévue
     
    Une Bévue, Apr 26, 2008
    #1
    1. Advertising

  2. Une Bévue

    Une Bévue Guest

    Une Bévue <> wrote:

    >
    > there is no DOM method for getting the root node, enabling not to
    > specify the root is svg|math ???



    req.responseXML.documentElement

    response given over the french clj (fr.c.l.j)

    --
    Une Bévue
     
    Une Bévue, Apr 26, 2008
    #2
    1. Advertising

  3. Une Bévue wrote:
    > at the page :
    > <http://thoraval.yvon.free.fr/Fixed_layout/import_nodes.xhtml>
    > when importing an svg document i have to do :
    > document.importNode(
    > req.responseXML.getElementsByTagName(req.parameters.root)[0],true))
    >
    > (lines 46/47)
    >
    > in case of SVG : req.parameters.root = 'svg'
    > and 'math' in case of MathML
    >
    >
    > there is no DOM method for getting the root node, enabling not to
    > specify the root is svg|math ???
    >
    > or could i do that using DOM/XPath ?
    >
    > ie something like :
    > req.responseXML.evaluate('/',document, nsResolver, XPathResult.ANY_TYPE,
    > null);
    >
    > ???


    The root element is simply accessible as
    req.responseXML.documentElement

    The root node in the XPath data model is the document node in the DOM
    model thus if you want to access the root node then you simply need
    req.responseXML
    However you can't import document nodes.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Apr 26, 2008
    #3
  4. Une Bévue

    Une Bévue Guest

    Martin Honnen <> wrote:

    >
    > The root element is simply accessible as
    > req.responseXML.documentElement
    >
    > The root node in the XPath data model is the document node in the DOM
    > model thus if you want to access the root node then you simply need
    > req.responseXML
    > However you can't import document nodes.


    OK, fine thanks !
    --
    Une Bévue
     
    Une Bévue, Apr 26, 2008
    #4
  5. * Une Bévue wrote in comp.lang.javascript:
    >at the page :
    ><http://thoraval.yvon.free.fr/Fixed_layout/import_nodes.xhtml>
    >when importing an svg document i have to do :
    >document.importNode(
    >req.responseXML.getElementsByTagName(req.parameters.root)[0],true))
    >
    >(lines 46/47)
    >
    >in case of SVG : req.parameters.root = 'svg'
    >and 'math' in case of MathML


    When dealing with elements in a namespace you should instead use the
    method getElementsByTagNameNS() and properly specify the namespace in
    addition to the local name, like

    .getElementsByTagNameNS('http://www.w3.org/2000/svg', 'svg');

    >or could i do that using DOM/XPath ?
    >
    >ie something like :
    >req.responseXML.evaluate('/',document, nsResolver, XPathResult.ANY_TYPE,
    >null);


    You would select '/*' to get the root element as opposed to the root
    node.
    --
    Björn Höhrmann · mailto: · http://bjoern.hoehrmann.de
    Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
    68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
     
    Bjoern Hoehrmann, Apr 26, 2008
    #5
  6. Une Bévue

    Une Bévue Guest

    Bjoern Hoehrmann <> wrote:

    >
    > When dealing with elements in a namespace you should instead use the
    > method getElementsByTagNameNS() and properly specify the namespace in
    > addition to the local name, like
    >
    > .getElementsByTagNameNS('http://www.w3.org/2000/svg', 'svg');


    OK, then, i do have to assume i was somehow "lucky" when not specifying
    the ns ? (that works without it)

    > >or could i do that using DOM/XPath ?
    > >
    > >ie something like :
    > >req.responseXML.evaluate('/',document, nsResolver, XPathResult.ANY_TYPE,
    > >null);

    >
    > You would select '/*' to get the root element as opposed to the root
    > node.


    then a dom/xpath expression isn't equivalent to an xslt/xpath one ?

    i understand '/*' takes the root + everything below it.

    '/' takes the node only.

    and again, i'd have to specify the ns :

    '/xhtml|svg|math:*'

    this is unclear to me because when i specify '//xhtml:body' (for example
    in the dropdown at
    <http://thoraval.yvon.free.fr/Fixed_layout/editable_dropdown.xhtml> only
    tested on Mac OS X : firefox ans safari)

    i'm able to log the children and attributes.

    i think i misunderstood the difference between node and element...
    --
    Une Bévue
     
    Une Bévue, Apr 26, 2008
    #6
  7. * Une Bévue wrote in comp.lang.javascript:
    >then a dom/xpath expression isn't equivalent to an xslt/xpath one ?
    >
    >i understand '/*' takes the root + everything below it.


    No, this matches any element that is a child of the root node. There can
    only be one element with the root node as parent, the root element. This
    is the same wherever you use XPath. The root node and everything below
    it would be //node(), for example.

    >this is unclear to me because when i specify '//xhtml:body' (for example
    >in the dropdown at
    ><http://thoraval.yvon.free.fr/Fixed_layout/editable_dropdown.xhtml> only
    >tested on Mac OS X : firefox ans safari)


    But //* is very different from /*.
    --
    Björn Höhrmann · mailto: · http://bjoern.hoehrmann.de
    Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
    68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
     
    Bjoern Hoehrmann, Apr 26, 2008
    #7
  8. Une Bévue

    Une Bévue Guest

    Bjoern Hoehrmann <> wrote:

    >
    > No, this matches any element that is a child of the root node. There can
    > only be one element with the root node as parent, the root element. This
    > is the same wherever you use XPath. The root node and everything below
    > it would be //node(), for example.


    OK, clear enough, thanks !
    >
    > >this is unclear to me because when i specify '//xhtml:body' (for example
    > >in the dropdown at
    > ><http://thoraval.yvon.free.fr/Fixed_layout/editable_dropdown.xhtml> only
    > >tested on Mac OS X : firefox ans safari)

    >
    > But //* is very different from /*.


    yes clearly ))
    --
    Une Bévue
     
    Une Bévue, Apr 26, 2008
    #8
  9. Une Bévue schrieb am 26.04.2008 19:02:
    > Bjoern Hoehrmann <> wrote:


    > this is unclear to me because when i specify '//xhtml:body' (for example
    > in the dropdown at
    > <http://thoraval.yvon.free.fr/Fixed_layout/editable_dropdown.xhtml> only
    > tested on Mac OS X : firefox ans safari)


    Just for your Information:

    Internet Explorer gives a download Requester for each xhtml file (sent
    by xhtml+xml)

    http://blogs.msdn.com/ie/archive/2005/09/15/467901.aspx

    --
    Mit freundlichen Grüßen
    Holger Jeromin
     
    Holger Jeromin, Apr 26, 2008
    #9
  10. Une Bévue

    Une Bévue Guest

    Holger Jeromin <> wrote:

    >
    > Internet Explorer gives a download Requester for each xhtml file (sent
    > by xhtml+xml)


    yes, i know even if i can't test over win* ...

    but could i implement xhtml served as text/html with more than 4
    namespaces ???

    vielen dank ;-)
    --
    Une Bévue
     
    Une Bévue, Apr 26, 2008
    #10
  11. Une Bévue schrieb am 26.04.2008 20:46:
    > Holger Jeromin <> wrote:
    >> Internet Explorer gives a download Requester for each xhtml file (sent
    >> by xhtml+xml)

    > yes, i know even if i can't test over win* ...
    >
    > but could i implement xhtml served as text/html with more than 4
    > namespaces ???


    you can, but it is not nice and can only used for IE, because Opera und
    FF don't support this as a HTML mess.

    > vielen dank ;-)


    :)

    --
    Mit freundlichen Grüßen
    Holger Jeromin
     
    Holger Jeromin, Apr 26, 2008
    #11
  12. Une Bévue

    Une Bévue Guest

    Holger Jeromin <> wrote:

    >
    > you can, but it is not nice and can only used for IE, because Opera und
    > FF don't support this as a HTML mess.


    OK, seems strange to me the fact the guys of Microsoft have less man
    power than Apple for that kind of things...

    they argue about "improving our CSS support" and html parser where i
    discovered today the latest WebKit (safari) even the Gtk version for
    gnome is 100% Acid3 test successfull...

    tchuss !

    --
    Une Bévue
     
    Une Bévue, Apr 26, 2008
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,569
  2. Andy Fish

    performance of importNode

    Andy Fish, Nov 4, 2003, in forum: XML
    Replies:
    0
    Views:
    655
    Andy Fish
    Nov 4, 2003
  3. Tjerk Wolterink
    Replies:
    2
    Views:
    1,459
    Dimitre Novatchev
    Aug 24, 2006
  4. Simon Brooke
    Replies:
    10
    Views:
    1,144
    Joe Kesselman
    Mar 17, 2007
  5. Replies:
    1
    Views:
    576
    Martin Honnen
    May 8, 2007
Loading...

Share This Page