Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   search inside xml with javascript (FF and IE) (http://www.velocityreviews.com/forums/t928945-search-inside-xml-with-javascript-ff-and-ie.html)

quindo@gmail.com 12-28-2006 01:12 PM

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


Martin Honnen 12-28-2006 01:49 PM

Re: search inside xml with javascript (FF and IE)
 
quindo@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/

Quindo 12-28-2006 01:59 PM

Re: search inside xml with javascript (FF and IE)
 
On Dec 28, 2:49 pm, Martin Honnen <mahotr...@yahoo.de> wrote:
> 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



All times are GMT. The time now is 08:03 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.