473,385 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Using XPATH in Mozilla

I have created an ajax application which retrievs an xml file and fills in the tab fields on the form.The code works fine in IE while its does not in Mozilla. Can you please let me know if i have to install some plugins to use XPATH?


[HTML]<html>
<head>
<title>SilverLine </title>
<link rel="stylesheet" href="example.css" TYPE="text/css" MEDIA="screen">
<script type="text/javascript">

/* Optional: Temporarily hide the "tabber" class so it does not "flash"
on the page as plain HTML. After tabber runs, the class is changed
to "tabberlive" and it will appear.
*/
document.write('<style type="text/css">.tabber{display:none;}<\/style>');

var tabberOptions = {

/* Optional: instead of letting tabber run during the onload event,
we'll start it up manually. This can be useful because the onload
even runs after all the images have finished loading, and we can
run tabber at the bottom of our page to start it up faster. See the
bottom of this page for more info. Note: this variable must be set
BEFORE you include tabber.js.
*/
'manualStartup':true

};

</script>

<!-- Load the tabber code -->
<script type="text/javascript" src="tabber.js"></script>

<script type="text/javascript">
var request = false;
function getRequestObject() {

if (navigator.userAgent.indexOf("MSIE")>=0) {
var strName="Msxml2.XMLHTTP";
if (navigator.appVersion.indexOf("MSIE 5.5")>=0) {
strName="Microsoft.XMLHTTP";
}
try {
objXmlHttp=new ActiveXObject(strName);
alert ("strName"+strName);
return objXmlHttp;
} catch(e) {
alert("Error. Scripting for ActiveX might be disabled") ;

return;
}
}
if (navigator.userAgent.indexOf("Mozilla")>=0) {
objXmlHttp=new XMLHttpRequest();
alert("mozilla");
return objXmlHttp;
}
}

function createDocument(){

var aVersions = ["MSXML2.DOMDocument.5.0","MSXML2.DOMDocument.4.0", "MSXML2.DOMDocument.3.0",
"MSXML2.DOMDocument","Microsoft.XmlDom"];
if (window.ActiveXObject)
{

for(var i = 0;i<aVersions.length ; i++){

try{

var oXmlDom = new ActiveXObject(aVersions[i]);
//alert("returning .."+i+" "+oXmlDom);
return oXmlDom;
}catch(oError){

}
}
throw new Error ("MSXML is not installed ");

}

else if (document.implementation && document.implementation.createDocument)
{
var xmlDoc=document.implementation.createDocument(""," ",null);
return xmlDoc;
}
else
{
alert ("no");
alert('Your browser cannot handle this script');
}

}

function updateTabInfo() {

if ((request.readyState == 4) && (request.status == 200)) {

var xmlDoc = request.responseXML;
var oXmlDom = createDocument();
alert ("oxml"+oXmlDom);
oXmlDom.load(xmlDoc);
oXmlDom.setProperty("SelectionLanguage", "XPath");

var noOfgroups = oXmlDom.selectNodes("//user/groups/group").length;
var noOfChannels = oXmlDom.selectNodes("//user/channels/channel").length;
var noOfClouds = oXmlDom.selectNodes("//user/clouds/cloud").length;



var oRoot = oXmlDom.documentElement;
var noOfChildren = oRoot.childNodes.length; //groups, channels, clouds

var groupRoot = oRoot.childNodes[0];

alert ("noOfgroups"+noOfgroups);
document.getElementById("group").innerHTML = noOfgroups;
}

}
function callServer(){

// Build the URL to connect to

var url = "http://localhost/user/ABC";

request = getRequestObject();

alert ("req"+request);
// Open a connection to the server
request.open("GET", url, true);

// Set up a function for the server to run when it's done
request.onreadystatechange = updateTabInfo;

// Send the request
request.send(null);



}
</script>

</head>
<body>
<form name="Login" method="post" >

<div class="tabber">


<div class="tabbertab" id = "group">
<h2>Groups</h2>
<p>Group details.</p>
</div>


<div class="tabbertab" id = "channel">

<h2>Channels</h2>
<p>Channel details.</p>
</div>

<div class="tabbertab" id = "cloud">

<h2>Clouds</h2>
<p>Cloud details.</p>
</div>

<div class="tabbertab" id="trend">
<h2>Trends</h2>
<p>User details.</p>

</div>


</div>
<script type="text/javascript">

/* Since we specified manualStartup=true, tabber will not run after
the onload event. Instead let's run it now, to prevent any delay
while images load.
*/

tabberAutomatic(tabberOptions);

</script>
<input type="submit" name="submit" value="submit"> <br>
UserName<input type="text" name="UserName" onChange="callServer();" /><br>
<span id="ReturnedData"></span>
</body>
</html>



The XML file is

Code: ( text )
<?xml version = "1.0" encoding = "UTF-8"?>
<user id ='ABC' name = 'BBBBB BBB'>
<groups>
<group id = 'SL' name = 'SL group'>
<userlist>
<userid id ='RR' name = 'RR'/>
<userid id ='SS' name = 'SS'/>
</userlist>
</group>
<group id = 'NN' name = 'NN group'>
<userlist>
</userlist>
</group>
<group id = 'Web2.0' name = 'Web 2.0 Interest Group'>
<userlist>
<userid id ='SS' name = 'SSSSSS''/>
<userid id ='NN' name = 'NNN'/>
</userlist>
</group>
</groups>
<channels>
<channel id ='CNN' name = 'CNN in June' url ='http://www.ibm.com/developerworks/news/dw_dwtp.rss' start='2007-06-01'/>
</channels>
<clouds>
<cloudid id ='cnn-in-oct' name = 'CNN in October'/>
<cloudid id ='Google-Jan' name = 'Google tags'/>
<cloudid id ='HBO-movies' name = 'HBO movie schedule'/>
</clouds>
</user>[/HTML]
Jun 28 '07 #1
1 2322
acoder
16,027 Expert Mod 8TB
See if this link helps. Also, see the follow-up in the Mozilla documentation.

Try to support as many browsers as possible by using object detection rather than browser detection, e.g. you could've checked for the XMLHttpRequest object:
Expand|Select|Wrap|Line Numbers
  1. if(window.XMLHttpRequest) {
or use try/catch.
Jun 29 '07 #2

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

Similar topics

2
by: Neil Zanella | last post by:
Hello, I would like to know whether the mozilla web browser has built in support for searching XML documents via XPath expressions as with IE's xmlobject's and xmlDoc's function selectNodes() or...
1
by: DV | last post by:
Hello, can anyone tell me or point me to somewhere what the exact differences (in terms of when would I use what) between XPath, XLink, XPointer and DOM are? Does it require special software...
6
by: Scott Simpson | last post by:
What is a good tool for running XPath queries on Linux? I have the O'Reilly XPath book and I'm using XPath Visualizer on Windows and that seems to work fine, but I'm looking for something on Linux....
1
by: Marek Mänd | last post by:
<style> .marek{} </style> etc.. <root> <element class="marek mand"/> <element class="mand marek blah"/> <element class="mand marekmänd"/> <element class="mand marekk"/> </root>
5
by: sniper | last post by:
hi ; i have this small code that consist in taking the name of the user and writing it in the same form as an output.the name is relative to /data/valid/string1 In my Js code i want to access the...
6
by: Hoss | last post by:
Hello. Because IE and Mozilla have such completely different XML implementations, I have created a class to handle general XML tasks, such as iterating over nodes given an xpath, evaluating an...
7
by: Duncan Smith | last post by:
Suppose I have the following XML doc: <root> <tag id="1"> <number value="1"/> </tag> <tag id="2"> <something/> </tag> <tag id="3">
1
by: newToAjax | last post by:
Hi , Can someone tell me how i can use xpath in javascript and also make sure that it works in all browsers? I seem to have got it right in IE , but it fails in mozilla. How do i use xpath in...
7
by: kaer | last post by:
I have to send an XPath request on web page with JavaScript (with XMLHttpRequest) that has to be executed before. I have no idea on how to do that. Any pointer is welcome.
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.