Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder Skyzyx's Avatar
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Case-Sensitivity of getElementsByTagName

    I'm working on developing an RSS/RDF/Atom Parser in JavaScript. I've already successfully implemented complete support for RSS 0.9x and 2.0. So far, so good. However, I've run into two minor problems. One is mentioned here, and one is in another post.

    The issue that I'm coming across is the case-sensitivity of getElementsByTagName() when parsing standard RSS (XML) tags.

    Danny Goodman's JavaScript Bible says that the tag name string that gets passed as the parameter in getElementsByTagName() is case-insensitive. However, this is speaking in terms of HTML and the HTML DOM. I'm working with XML, and getElementsByTagName is handling the XML tags as being case-sensitive.

    Can someone suggest a way around this? Can a regular expression be used as the parameter? If so, what would the syntax be (as I'm not very familiar with regex)? For example, I want a <textinput> tag to be handled the same as <textInput> (which is the correct syntax).

    Creator of SimplePie and Tarzan AWS, co-founder of WarpShare, co-built the Y! Messenger website, usability-focused, and an INFJ personality.

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeċ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Nope, it can't be used. The regex will be converted using the toString method into a string (/pattern/ --> '/pattern/'). I think your best choice would be to iterate over document.getElementsByTagName('*') with a regexp comparison, unless you want to support only Moz, in which case There Is Another Way&trade;.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Regular Coder Skyzyx's Avatar
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The intention of this library is to be used in HTA's or Gecko Applications. I was hoping to be able to keep equal support for IE6 and Moz, but if that isn't the case, then it isn't the case. I keep finding myself getting frusterated over IE's lack of support for basic things... like parsing XML tags with/without namespaces attached. Argh!

    Anyways, I'd be interested in The Better Way™, if you've got some ideas...

    Creator of SimplePie and Tarzan AWS, co-founder of WarpShare, co-built the Y! Messenger website, usability-focused, and an INFJ personality.

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeċ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Hmm, I haven't played with them much, but you can use the [DOM2 Transversal] NodeFilters and TreeWalkers for it, they are supported in moz. <http://w3.org/dom/DOMTR> has lists all the DOM technical reports, including the Transversal & Range one, if you need to find the specification on it.

    As for help, ask JKD. He's the only one I know of on the forums that knows the workings of these. (I think I could figure them out, though, given some time to work on it.)
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    Regular Coder Skyzyx's Avatar
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by liorean
    I think your best choice would be to iterate over document.getElementsByTagName('*') with a regexp comparison...
    I'm open to suggestions at the moment. I'd really like to add this kind of support, but in something like this, I've got no idea where to begin.

    Any code bits would be tremendously helpful. Thanks.

    Creator of SimplePie and Tarzan AWS, co-founder of WarpShare, co-built the Y! Messenger website, usability-focused, and an INFJ personality.

  • #6
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeċ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Hmm, the most common ones are textinput and textInput, right? You could circle two collections, one each.

    Or, you could do it this way:
    Code:
    var
        aTextInputs=[],
        i=0,
       oTemp;
    while((temp=document.getElementsByTagName('*').item(i++)))
        if(/^(rss:)?textinput$/i.test(oTemp.nodeValue))
            aTextInputs.push(oTemp);
    Last edited by liorean; 02-11-2004 at 12:38 AM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #7
    Regular Coder Skyzyx's Avatar
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm a bit sketchy on how to implement this. Would I use it as a function? What would some context be for implementing this? Am I supposed to use the smiley face too?

    Creator of SimplePie and Tarzan AWS, co-founder of WarpShare, co-built the Y! Messenger website, usability-focused, and an INFJ personality.

  • #8
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeċ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts

    Smile No smiley:)

    Since it's RSS you're handling, and you aren't likely to encounter dynamic RSS, I believe you could make it a run-once code. The aTextInputs variable will be an array containing all elements matching /[tT][eE][xX][tT][iI][nN][pP][uU][tT]/, possibly with a namespace of /[rR][sS][sS]/ before it. In source order.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #9
    Regular Coder Skyzyx's Avatar
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So, would I run it before the parsing or after? If it'll help (which I think it will), download the latest version of Feed Parser and take a look at the code. It might help you give me some much appreciated insight.

    Creator of SimplePie and Tarzan AWS, co-founder of WarpShare, co-built the Y! Messenger website, usability-focused, and an INFJ personality.

  • #10
    Regular Coder Skyzyx's Avatar
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    liorean,

    I've implemented the following block of code into my parser:
    Code:
    getChildrenByTagName(oParent, sTagName){
        var
            i=0,
            aResults=[],
            oTemp;
        while((oTemp=oParent.childNodes.item(i++)))
            if(oTemp.nodeName==sTagName)
                aResults.push(oTemp);
        return aResults;
    }
    It works beautifully. Thank you. In another thread, you gave me this code for being able to handle textinput and textInput as being the same. More specifically [Tt][Ee][Xx][Tt][Ii][Nn][Pp][Uu][Tt] is all handled the same.
    Code:
    var
        aTextInputs=[],
        i=0,
       oTemp;
    while((temp=document.getElementsByTagName('*').item(i++)))
        if(/^(rss:)?textinput$/i.test(oTemp.nodeValue))
            aTextInputs.push(oTemp);
    Is there a way to integrate these two scripts together so that the child node name can be grabbed as lowercase without a problem. The code between the two looks very similar, but the JS involved in these two snippets are a bit over my head right now. :p

    I'd like to have this:
    Code:
    getChildrenByTagName(oParentObject, 'textinput')[0].firstChild.data;
    ...be able to grab the data from within either <textInput> or <textinput> or <TEXTINPUT> or <tExTiNpUt> tags.

    Any ideas?

    Creator of SimplePie and Tarzan AWS, co-founder of WarpShare, co-built the Y! Messenger website, usability-focused, and an INFJ personality.

  • #11
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeċ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    This is untested and doesn't handle all cases, but it should be enough for what you need. Try it...
    Code:
    getChildrenByTagName(oParent, sTagName, bCaseSensitive){
        var
            i=0,
            aResults=[],
            oTemp,
            reTagName=new RegExp('^'+(/:/.test(sTagName)?'(rss)?':'')+sTagName+'$',
            (bCaseSensitive?'i':'';));
            while((oTemp=oParent.childNodes.item(i++)))
                if(reTagName.test(oTemp.nodeName))
                    aResults.push(oTemp);
        return aResults;
    }
    Last edited by liorean; 03-17-2004 at 10:34 PM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #12
    Regular Coder Skyzyx's Avatar
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It needed just a smidge of tweaking, but it appears to work exactly as I'd like it to.

    You're the best!

    EDIT: To clarify for others, first off, there are no RSS tags or attributes that have an rss: namespace. Therefore, that part of the code is unnecessary, so I stripped it all out.

    Secondly, Gecko (the rendering engine I'm designing for) is able to get to tags with or without including a namespace. In other words, document.getElementsByTagName('mytag')[0] will get <mytag>, <rdf:mytag>, <dc:mytag>, etc.

    Internet Explorer, on the other hand, requires that you include the namespace and colon in the requesting of the tag. I'm not sure if this is a poor implementation, or if it was done like this on purpose.

    Anyways, thanks again.
    Last edited by Skyzyx; 03-18-2004 at 01:01 AM.

    Creator of SimplePie and Tarzan AWS, co-founder of WarpShare, co-built the Y! Messenger website, usability-focused, and an INFJ personality.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •