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

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 :
SelectSingleNode("/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 4053
qu****@gmail.com wrote:
Serverside I would have done that using XPath :
SelectSingleNode("/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.responseXML.evaluate(
"/company/equipment[trackno='4']/icode",
httpRequest.responseXML,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue;
if (icode != null) {
// now access e.g. icode.textContent
}

IE 6 and later use MSXML 3 to have XPath support so there you would do e.g.
var xmlDoc = httpRequest.responseXML;
xmlDoc.setProperty('SelectionLanguage', 'XPath');
var icode =
xmlDoc.selectSingleNode("/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...@yahoo.dewrote:
qui...@gmail.com wrote:
Serverside I would have done that using XPath :
SelectSingleNode("/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.responseXML.evaluate(
"/company/equipment[trackno='4']/icode",
httpRequest.responseXML,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue;
if (icode != null) {
// now access e.g. icode.textContent
}

IE 6 and later use MSXML 3 to have XPath support so there you would do e.g.
var xmlDoc = httpRequest.responseXML;
xmlDoc.setProperty('SelectionLanguage', 'XPath');
var icode =
xmlDoc.selectSingleNode("/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
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"); ...
3
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...
4
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...
7
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...
1
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...
1
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...
8
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...
0
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,...
0
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...
0
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...

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.