Making an Array from an XML with Firefox vs Explorer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • djmanfros
    New Member
    • Oct 2007
    • 2

    #1

    Making an Array from an XML with Firefox vs Explorer

    Hello!

    I've an XML like this:

    [CODE=xml]<XML id=SlideShowDat a>
    <SlideShowDat a>
    <SLIDES>
    <SLIDE FileName="filen ame1.jpg" Caption="descri zione1"/>
    <SLIDE FileName="filen ame2.jpg" Caption="descri zione2"/>
    </SLIDES>
    </SlideShowData>
    </XML>
    [/CODE]
    My javascript should create an Array from this XML. It works with Explorer while returns "parent has no properties" error with Firefox.

    This is the two functions:

    [CODE=javascript]function InitSlideData()
    {var SlidesNode =
    FindChildNode(S lideShowData.do cumentElement, "SLIDES");
    if (SlidesNode == null)
    return;
    var ChildNodes = SlidesNode.getE lementsByTagNam e("SLIDE");

    for (i = 0; i < ChildNodes.leng th; i++)
    {SlideImages[i] = ChildNodes.item (i).attributes. getNamedItem("F ileName").value ;
    SlideCaptions[i] = ChildNodes.item (i).attributes. getNamedItem("C aption").value;
    }
    }

    function FindChildNode(p arent, name)
    { var ChildNodes = parent.getEleme ntsByTagName(na me); //here occurs the error!!
    for (i = 0; i < ChildNodes.leng th; i++)
    if (ChildNodes.ite m(i).nodeName == name)
    return ChildNodes.item (i);
    return null;
    }[/CODE]

    Please help me, thankyou in advance!
    Em
    Last edited by acoder; Oct 16 '07, 06:52 PM. Reason: Added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    On line 3, you use the variable SlideShowData. Where is it defined?

    Comment

    • djmanfros
      New Member
      • Oct 2007
      • 2

      #3
      Originally posted by acoder
      On line 3, you use the variable SlideShowData. Where is it defined?
      It's not defined.
      Isn't enough <XML id=SlideShowDat a>?
      How should I define it?
      Why with IExplorer it works?

      thank you very much!
      EM

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You can define it using:
        [CODE=javascript]var SlideShowData = document.getEle mentById("Slide ShowData");[/CODE] I shouldn't work in IE either, but it messes things up with IDs by making them accessible globally.

        Comment

        Working...