getElementsByTagName select element weirdness

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andy Chambers

    getElementsByTagName select element weirdness

    Hi,

    On both Opera and Firefox, getElementsByTa gName doesn't find anything
    apart from <optionelemen ts inside a select element. Why is this?
    Here's a page that demonstrates this behaviour. I'd have thought the
    correct behaviour would be to show "count: 1" but instead, you get
    "count: 2".

    Is this because only <option>s <select>s?

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>
    </title>
    <script type='text/javascript'>
    window.onload = function() {
    var elems = document.getEle mentsByTagName( "xref");
    alert("count: " + elems.length);
    };
    </script>
    <style type='text/css'></style>
    </head>
    <body>
    <div id='banner'>
    <h1>
    </h1>
    </div>
    <div id='content'>
    <select>
    <xref ref="1"/>
    </select>
    </div>
    </body>
    </html>


    Cheers,
    Andy
  • Thomas 'PointedEars' Lahn

    #2
    Re: getElementsByTa gName select element weirdness

    Andy Chambers wrote:
    On both Opera and Firefox, getElementsByTa gName doesn't find anything
    apart from <optionelemen ts inside a select element. Why is this?
    You are trying to use extended XHTML, and your markup is not Valid.[1] The
    "Extensible " in XHTML does _not_ mean "anything goes"; if you want to extend
    XHTML, you need to declare a namespace for all non-XHTML elements and
    attributes and a DTD or a Schema that declares these elements and
    attributes. And of course you must comply with the XHTML DTD (that you
    missed to declare here), which says in your case (assuming XHTML 1.0
    Transitional or Strict):

    | <!ELEMENT select (optgroup|optio n)+ <!-- option selector -->

    Meaning that an XHTML `select' element must contain at least one of
    `optgroup' or `option' elements.
    [...]
    Is this because only <option>s <select>s?
    Parse error.
    <html xmlns="http://www.w3.org/1999/xhtml">
    This declares the XHTML namespace as the default namespace.
    [...]
    var elems = document.getEle mentsByTagName( "xref");
    [...]
    <body>
    [...]
    <select>
    <xref ref="1"/>
    </select>
    [...]
    </body>
    </html>
    Therefore, you need to use namespace-based accessor methods in an XHTML
    document. Suppose your `xref' element was declared in
    <http://achambers.me.uk/dtds/ac.dtdlike this:

    ...
    <!ELEMENT select (optgroup|optio n|xref)+>
    ...
    <!ELEMENT xref EMPTY>
    <!ATTLIST xref
    ref CDATA #REQUIRED
    >
    ...

    And used like this:

    <DOCTYPE html PUBLIC "-//AChambers//DTD XHTML 1.0 plus ACMarkup//EN"
    "http://achambers.me.uk/dtds/xhtml1-acmarkup.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    xmlns:ac="http://achambers.me.uk/acmarkup"
    xml:lang="en">
    ...
    <body>
    ...
    <ac:xref ref="1"/>
    ...
    </body>
    </html>

    You would access it like this:

    var elem = document.getEle mentsByTagNameN S(
    "http://achambers.me.uk/acmarkup", "xref")[0];


    PointedEars
    ___________
    [1] <http://validator.w3.or g/>
    --
    Prototype.js was written by people who don't know javascript for people
    who don't know javascript. People who don't know javascript are not
    the best source of advice on designing systems that use javascript.
    -- Richard Cornford, cljs, <f806at$ail$1$8 300dec7@news.de mon.co.uk>

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: getElementsByTa gName select element weirdness

      Thomas 'PointedEars' Lahn wrote:
      [...] Suppose your `xref' element was declared in
      <http://achambers.me.uk/dtds/ac.dtdlike this:
      >
      [...]
      And used like this:
      >
      <DOCTYPE html PUBLIC "-//AChambers//DTD XHTML 1.0 plus ACMarkup//EN"
      "http://achambers.me.uk/dtds/xhtml1-acmarkup.dtd">
      [...]
      Those two URIs must be the same, of course.


      PointedEars
      --
      realism: HTML 4.01 Strict
      evangelism: XHTML 1.0 Strict
      madness: XHTML 1.1 as application/xhtml+xml
      -- Bjoern Hoehrmann

      Comment

      • Andy Chambers

        #4
        Re: getElementsByTa gName select element weirdness

        Thomas 'PointedEars' Lahn wrote:
        <DOCTYPE html PUBLIC "-//AChambers//DTD XHTML 1.0 plus ACMarkup//EN"
        "http://achambers.me.uk/dtds/xhtml1-acmarkup.dtd">
        [...]
        >
        Those two URIs must be the same, of course.
        So does the browser actually lookup the DTD and validate the document
        before loading it? Does it have to be a DTD or could it be something
        else that defines your allowable elements (e.g. relaxng or w3c
        schema).

        Is it possible to extend plain old html in this way or is that the
        whole point of xhtml?

        Cheers,
        Andy

        Comment

        • Martin Honnen

          #5
          Re: getElementsByTa gName select element weirdness

          Andy Chambers wrote:
          On both Opera and Firefox, getElementsByTa gName doesn't find anything
          apart from <optionelemen ts inside a select element. Why is this?
          Here's a page that demonstrates this behaviour. I'd have thought the
          correct behaviour would be to show "count: 1" but instead, you get
          "count: 2".
          Do you serve the document as text/html or as application/xhtml+xml or
          application/xml or text/xml?
          Why do you say "doesn't find anything" if count is 2?



          --

          Martin Honnen

          Comment

          • RobG

            #6
            Re: getElementsByTa gName select element weirdness

            Andy Chambers wrote:
            Thomas 'PointedEars' Lahn wrote:
            >
            >><DOCTYPE html PUBLIC "-//AChambers//DTD XHTML 1.0 plus ACMarkup//EN"
            >> "http://achambers.me.uk/dtds/xhtml1-acmarkup.dtd">
            >>[...]
            >Those two URIs must be the same, of course.
            >
            So does the browser actually lookup the DTD and validate the document
            before loading it? Does it have to be a DTD or could it be something
            else that defines your allowable elements (e.g. relaxng or w3c
            schema).
            >
            Is it possible to extend plain old html in this way or is that the
            whole point of xhtml?

            That is getting OT for this news group, though some here likely know the
            answer. Try:

            news:comp.infos ystems.www.authoring.html


            But beware, some there have a passionate dislike of XHTML (which is not
            a hint to not post, only to be tolerant of some replies you'll get). :-)


            --
            Rob

            Comment

            Working...