473,387 Members | 1,530 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,387 software developers and data experts.

reading xml values through javascript

hi
I am trying to get xml values into javascript I have been trying to get xml values through javascript and it is working fine in IE but not in firefox.
here are the javascript code
Expand|Select|Wrap|Line Numbers
  1. var xmlreq = false;
  2. //xmlreq =document.implementation.createDocument("","",null);
  3. xmlreq = new ActiveXObject("Microsoft.XMLDOM");
  4. var xmlFile="/val/valid.xml";
  5. var vale="";
  6. xmlreq.async="false";
  7. xmlreq.onreadystatechange=verify();
  8. xmlreq.load(xmlFile);
  9.  var xmlDoc =xmlreq.documentElement;
  10.  
  11. vale=xmlDoc.getElementsByTagName('firstcheck')[0].firstChild.nodeValue;
  12.  
  13. // i need to get the values from xml to this variable "vale" 
  14.  
  15. function verify() { 
  16.  if (xmlreq.readyState != 4) { 
  17. return false; 
  18.  } 
  19.  alert(xmlreq.readyState);
  20. }
my xml file is, "valid.xml"

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <validationcheck>
  3.     <firstcheck>check</firstcheck>
  4.     <firstcheck>venki</firstcheck>
  5.  
  6. </validationcheck>
The above code is working fine with IE .I also tried to work with firefox with these code

xmlreq =document.implementation.createDocument("","",null );
but after load,
xmlreq.load(xmlFile);
var xmlDoc =xmlreq.documentElement;
if i alert xmlDoc
it gives null , and error is xmldoc has no properties.please help me
Dec 4 '08 #1
3 1877
acoder
16,027 Expert Mod 8TB
See this tutorial.
Dec 4 '08 #2
gits
5,390 Expert Mod 4TB
especially have an eye on the 'async' property :) in the mentioned tutorial ...
Dec 4 '08 #3
Hi
Thank u for u suggestion .I worked out in another method and works here are solution ,

function getSalesTotal()

{
url = "/corporate/commonjs/YUI_js/validation/valid.xml";
// AJAX code for Mozilla, Safari, Opera etc.
if (window.XMLHttpRequest) {


xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = xmlhttpChange;
xmlhttp.open("GET", url, true);
xmlhttp.send(null);
}
// AJAX code for IE
else if (window.ActiveXObject) {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
if (xmlhttp)
{
xmlhttp.onreadystatechange = xmlhttpChange;
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
}
}

function xmlhttpChange()
{
first=1;
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
xmlhttp.responseXML.getElementsByTagName('required ')[select].firstChild.data
}
}
}
getSalesTotal();
xmlhttp.async="false";
xmlhttpChange();
the results are obtained through
xmlhttp.responseXML.getElementsByTagName('required ')[select].firstChild.data
in the above code [select] value will be eithe 0 or 1.I need to get either english or japanese words from xml.so depending upon browser language i will get the values from the xml file.
Dec 11 '08 #4

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

Similar topics

6
by: Eddie | last post by:
When I use JavaScript to read an element's textDecoration style, I only get one value even if there are more than one in the sytle sheet. For example if the text-decoration is defined as:...
1
by: Roger Godefroy | last post by:
Hi there... I want to read fieldvalues from out of a dynamicaly created table (php). But this has to be done by JavaScript. Every row of the table has a select-box, inputbox and a order-button....
1
by: Randell D. | last post by:
HELP! I am determined to stick with this... I'm getting there... for those who haven't read my earlier posts, I'm createing what should be a simple function that I can call to check that...
12
by: Anna | last post by:
Hi all, I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try.... in case you should see it later I apologize for posting the same...
1
by: imxuf | last post by:
I have an Active Server Page with embedded Javascript that allows th user to update certain values dynamically. e.g. window.document.myForm.myTextbox.value = "some new value"; However, when...
5
by: Dennis Fazekas | last post by:
Greetings, I am creating a web form which will all the user to add an unlimited number of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to remove, and a "Save" button....
1
by: waynes | last post by:
Hello group, first time here. I have question regarding reading form post variables. I have a forms processor that dynamically reads a form, for example: For x = 1 To Request.Form.count() ...
1
by: bookimal | last post by:
Hi, I'm not sure whether this goes in the XML or the Javascript forum but I guess its more Javascript because I want to read an XML file.. Anyway... I've got an XML file in this form: ...
8
by: LayneMitch via WebmasterKB.com | last post by:
I'm supposed to develop a page that asks info as form values and when you hit "submit" it takes you to a page that reads the values you entered into the first page and displays those values in a...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.