473,554 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to read data from XMLDocument by using Javascript

3 New Member
hi

how to read data from XMLDocument by using Javascript. i got coding from internet. but its not read data. help me

its in JavaScript
-----------------------

Expand|Select|Wrap|Line Numbers
  1. //server return XML Document
  2.  
  3. var xmlDoc=xmlHttp.responseXML.documentElement;
  4.  
  5. document.getElementById("companyname").innerHTML= 
  6. xmlDoc.getElementsByTagName("compname")[0].childNodes[0].nodeValue; 
  7.     --- this line is used for read data from xmldocument. its correct or not'
  8.  
  9. document.getElementById("contactname").innerHTML=
  10. xmlDoc.getElementsByTagName("contname")[0].childNodes[0].nodeValue;
  11. document.getElementById("address").innerHTML=
  12. xmlDoc.getElementsByTagName("address")[0].childNodes[0].nodeValue;
  13. document.getElementById("city").innerHTML=
  14. xmlDoc.getElementsByTagName("city")[0].childNodes[0].nodeValue;
  15. document.getElementById("country").innerHTML=
  16. xmlDoc.getElementsByTagName("country")[0].childNodes[0].nodeValue;
May 26 '07 #1
5 24382
acoder
16,027 Recognized Expert Moderator MVP
There may be problems with white-space nodes - see this link.
Jan 24 '08 #2
Hallow
2 New Member
Here is something which might help you: JavaScript Xml Document and XPath
Dec 29 '09 #3
udaypawar
29 New Member
Expand|Select|Wrap|Line Numbers
  1. function loadXMLString(xmlstring) {
  2.     if (window.DOMParser) {
  3.         parser=new DOMParser();
  4.         xmlDoc=parser.parseFromString(txt,"text/xml");
  5.     }
  6.     else // Internet Explorer
  7.     {
  8.         xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  9.         xmlDoc.async="false";
  10.         xmlDoc.loadXML(txt); 
  11.     }
  12.     return xmlDoc;
  13. }
  14.  
  15. var xmlDoc = loadXMLString("<a><b>1</b><b>2</b></a>") ;
  16. var objNodeList = xmlDoc.getElementsByTagName("a");
  17. alert(objNodeList.length);
Jan 1 '10 #4
xNephilimx
213 Recognized Expert New Member
You could also use jQuery, just wrap the xml code in the jquery object and you're ready to query it.

Best regards
Jan 4 '10 #5
Appeloappelo
1 New Member
Javascript for Selenium reading XML from DOM into XML string:
(when displaying xml file in a browser)

Expand|Select|Wrap|Line Numbers
  1. function loadXMLFromDOM2XMLString( xmlString, xmltag, currentChildNode ) { 
  2.  
  3. var nodes = currentChildNode.childNodes; 
  4. var i = 0 ;
  5. var node = nodes[i];
  6. var slash = '/';
  7. var lessthan = '<';
  8. var greaterthan = '>';
  9. while ( i < nodes.length) {
  10.    if (node.data == null) {xmltag = lessthan+node.localName+greaterthan;} else {xmltag = node.data;};
  11.    xmlString = xmlString  + xmltag;
  12.    xmlString = loadXMLFromDOM2XMLString( xmlString, xmltag, node  );   
  13.    if (node.data == null) {xmltag = lessthan+slash+node.localName+greaterthan;} else {xmltag = "";};
  14.    xmlString = xmlString + xmltag;
  15.    i++;
  16.    node = nodes[i];
  17. }
  18.  return xmlString ;
  19. } ;
  20.  
  21. var xmlString = "";
  22. var xmltag = "";
  23. var currentChildNode = window.document;
  24.  
  25. xmlString = loadXMLFromDOM2XMLString( xmlString, xmltag, currentChildNode );
  26. xmlString;
Dec 24 '10 #6

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

Similar topics

5
6475
by: Tim | last post by:
I've been working on this for over a week now, and just can't get this figured out. Hoping one of you gurus can help me out here. I have an xml data island that I'm representing on an htm page as an expandable menu. Got that working, but now I need to add sorting and searching abilities to the menu. I am hoping to do this with xsl but can't...
2
6019
by: Graham Pengelly | last post by:
Hi I am trying to transform on System.Xml.XmlDocument into another using XslTransform without writing the object out to a file. I am guessing it should work something like this... public XmlDocument TransformXmlDoc(XmlDocument docToTransform, string xsltFilePath) { //load the xslt
7
4884
by: SQLScott | last post by:
I have a Web Service in which I am trying to pass an XMLDocument as a parameter to one of the methods. I would like to use the XMLTextReader to read the XML but I am getting the following error: Value of type System.xml.xmldocument cannot be converted to System.IO.textreader. I would think this is possible to do. Code snippet is below:
1
3428
by: Chua Wen Ching | last post by:
Hi there, I have some problems when reading XML file. 1. First this, is what i did, cause i can't seem to read "sub elements or tags" values, so i place those values into attributes like this. Before: ----------
4
22252
by: David Dvali | last post by:
Hello. I have such XML file: <root> <elem1> <optional> Some data <optional> </elem1> </root>
1
5324
by: vkrasner | last post by:
It works with VS2003 and does not in VS2005: in VS2003 : string sMyvalue = ConfigurationSettings.AppSettings; in VS2005 (does not work!!) string sMyvalue = ConfigurationManager.AppSettings; Anybody able to give me idea how-to read by C# element which I add to the machine.config into the new single section?
4
16681
by: Gerrit | last post by:
It must be simple, but I don't find how I can read a XmlFile in an ArrayList. Sample of my XmlFile: <?xml version="1.0" encoding="utf-8" ?> <Relations> <Person> <FirstName>John</FirstName> <LastName>Smith</LastName>
6
3208
by: =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?= | last post by:
Hi, can someone please let me know how I can read xml elements using object oriented program. I created a class to use the get and set properties however I dont know how I can pass the values from xml file to the class and use the values in my form. Thanks -- Nejadian
2
5317
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi Is there any way to Read an INIFile from a string or Stream instead of a physical file ??? I want to read the INIFile into a string then store in a db but when I read the string from the db or save string to the db I don't want to have to copy the string to a file to use the WritePrivateProfileString and GetPrivateProfileString. Is...
0
7603
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7529
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7806
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8047
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7568
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7891
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6151
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5159
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3568
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...

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.