By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,364 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,364 IT Pros & Developers. It's quick & easy.

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

P: 57
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=loadXMLDoc("sampleFileZ.xml");
x=xmlDoc.getElementsByTagName("sampleNode");
for (i=0;i<x.length;i++)
{
if (x[i].parentNode.hasAttribute("sampleAtt"))
{
document.write(x[i].childNodes[0].nodeValue)
document.write("<br />")
}
}
</script>

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

This one works in IE, but not FF:

<script language="JavaScript" type="text/javascript">
xmlDoc=loadXMLDoc("sampleFile.xml");
xmlDoc.setProperty("SelectionLanguage", "XPath");
x=xmlDoc.selectNodes("//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!
Apr 26 '07 #1
Share this Question
Share on Google+
2 Replies


drhowarddrfine
Expert 5K+
P: 7,435
Probably not the problem but this is not valid:
<script language="JavaScript" type="text/javascript">

Change it to:
<script type="text/javascript">
Apr 26 '07 #2

P: 57
npm
Thanks! I changed it.

Does anyone have a suggestion on how to work this out?
Apr 27 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.