473,545 Members | 1,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

search inside xml with javascript (FF and IE)

Hello,

I've searched the internet but couldn't find an answer so I'm hoping
someone here can help me.

A webpage recieves XML from the server using xmlhttp.
What I want to do is search in this xml browser-side.

XML-example:

<company>
<equipment>
<trackno>1</trackno>
<icode>ruthd</icode>
</equipment>
<equipment>
<trackno>4</trackno>
<icode>rdke</icode>
</equipment>
</company>

I want to display the icode from equipment with trackno 4.

Serverside I would have done that using XPath :
SelectSingleNod e("/company/equipment [trackno='4']/icode")

How do I do this in Browserside Javascript.
The code has to work in both FireFox and IE.

Greetings,
Pieter

Dec 28 '06 #1
2 4056
qu****@gmail.co m wrote:
Serverside I would have done that using XPath :
SelectSingleNod e("/company/equipment [trackno='4']/icode")

How do I do this in Browserside Javascript.
The code has to work in both FireFox and IE.
Firefox supports XPath using the W3C DOM Level 3 XPath API so you would
use e.g.
var icode = httpRequest.res ponseXML.evalua te(
"/company/equipment[trackno='4']/icode",
httpRequest.res ponseXML,
null,
XPathResult.FIR ST_ORDERED_NODE _TYPE,
null
).singleNodeVal ue;
if (icode != null) {
// now access e.g. icode.textConte nt
}

IE 6 and later use MSXML 3 to have XPath support so there you would do e.g.
var xmlDoc = httpRequest.res ponseXML;
xmlDoc.setPrope rty('SelectionL anguage', 'XPath');
var icode =
xmlDoc.selectSi ngleNode("/company/equipment[trackno='4']/icode");
if (icode != null) {
// now access e.g. icode.text
}

--

Martin Honnen
http://JavaScript.FAQTs.com/
Dec 28 '06 #2
On Dec 28, 2:49 pm, Martin Honnen <mahotr...@yaho o.dewrote:
qui...@gmail.co m wrote:
Serverside I would have done that using XPath :
SelectSingleNod e("/company/equipment [trackno='4']/icode")
How do I do this in Browserside Javascript.
The code has to work in both FireFox and IE.Firefox supports XPath using the W3C DOM Level 3 XPath API so you would
use e.g.
var icode = httpRequest.res ponseXML.evalua te(
"/company/equipment[trackno='4']/icode",
httpRequest.res ponseXML,
null,
XPathResult.FIR ST_ORDERED_NODE _TYPE,
null
).singleNodeVal ue;
if (icode != null) {
// now access e.g. icode.textConte nt
}

IE 6 and later use MSXML 3 to have XPath support so there you would do e.g.
var xmlDoc = httpRequest.res ponseXML;
xmlDoc.setPrope rty('SelectionL anguage', 'XPath');
var icode =
xmlDoc.selectSi ngleNode("/company/equipment[trackno='4']/icode");
if (icode != null) {
// now access e.g. icode.text
}
This looks like something I could use.
Thank You!

Pieter

Dec 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1580
by: Simon Wigzell | last post by:
I generate my webpages from a database. A good many of my links are popup links. For convenience I am using a javascript function to pop up the window e.g. popInternalWindow("Home"); popInternalWindow(pagename) { popupString = "<%=session("DomainName")%>" = "/" + pagename + ".htm"; pagename = window.open(popupString,pagename,'');
3
6541
by: Ya Ya | last post by:
I have a folder with a lot of PDF and CHM files. I would like to develope an ASP.net application that enables the user to search inside the content of those files. How do I search inside those type of files ? Thanks for your time ra294@hotmail.com
4
3853
by: lars.gundersen | last post by:
I need to find some kind of polygon map search JavaScript that allows me to draw a polygon on a map an passed it on so i can define a search from the coordinates Have anyone see any sites using this functionality or something similar?
7
1484
by: Matt Kruse | last post by:
Javascript "Knowledge Base" Search: http://www.javascripttoolbox.com/search/ Responses to questions on this group are often along the lines of "did you read the FAQ" or "did you search the archives?" or "did you do a google search?". To regular readers and experienced javascript developers, knowing how and where to search and filtering...
1
2412
by: Harry Haller | last post by:
What is the fastest way to search a client-side database? I have about 60-65 kb of data downloaded to the client which is present in 3 dynamically created list boxes. The boxes are filled from 3 string arrays, which are just lists of people or companies in alphabetic order. These names may have accented and umlauted characters (which are...
1
5598
by: lejason | last post by:
Hello, I am looking for a way to do a string search inside an xml. Basically, I work for a company that wants to export an XML file from and excel sheet and then have that data be presented on the web. Part of the presentation is that they want to be able to "search" for their favorite dealers. So, this will be a string search. The...
8
2940
by: frohlinger | last post by:
Hi, I have a search textbox in my website. I validate the search string with a "white list" of allowed characters: if((/^+$/).test(theSearchWord) == false) { return; }
0
10720
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not...
0
7396
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
5968
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...
1
5323
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4943
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
3449
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...
0
3440
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1874
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
700
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.