Display XML nodes whose parent node has a certain attribute (or attribute value)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • npm
    New Member
    • Apr 2007
    • 57

    Display XML nodes whose parent node has a certain attribute (or attribute value)

    I'm trying to display XML nodes whose parent node has a certain attribute (or attribute value). I have one code that works in Firefox, but not IE and another code that works in IE, but not Firefox.

    This one works in FF, but not IE:

    <script type="text/javascript">
    xmlDoc=loadXMLD oc("sampleFileZ .xml");
    x=xmlDoc.getEle mentsByTagName( "sampleNode ");
    for (i=0;i<x.length ;i++)
    {
    if (x[i].parentNode.has Attribute("samp leAtt"))
    {
    document.write( x[i].childNodes[0].nodeValue)
    document.write( "<br />")
    }
    }
    </script>

    ---------------------------------------

    This one works in IE, but not FF:

    <script language="JavaS cript" type="text/javascript">
    xmlDoc=loadXMLD oc("sampleFile. xml");
    xmlDoc.setPrope rty("SelectionL anguage", "XPath");
    x=xmlDoc.select Nodes("//node1[@att='value']/node2");
    for (i=0;i<x.length ;i++)
    {
    document.write( x[i].childNodes[0].nodeValue)
    document.write( "<br />")
    }
    </script>

    Is there one javascript (maybe one like the first one that uses an if statement) that will work in both browsers?

    Thanks so much!
  • drhowarddrfine
    Recognized Expert Expert
    • Sep 2006
    • 7434

    #2
    Probably not the problem but this is not valid:
    <script language="JavaS cript" type="text/javascript">

    Change it to:
    <script type="text/javascript">

    Comment

    • npm
      New Member
      • Apr 2007
      • 57

      #3
      Thanks! I changed it.

      Does anyone have a suggestion on how to work this out?

      Comment

      Working...