search inside xml with javascript (FF and IE)

Discussion in 'Javascript' started by quindo@gmail.com, Dec 28, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. 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/
     
    Martin Honnen, Dec 28, 2006
    #2
    1. Advertising

  3. Quindo Guest

    On Dec 28, 2:49 pm, Martin Honnen <> wrote:
    > 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
     
    Quindo, Dec 28, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Dorward
    Replies:
    1
    Views:
    2,136
    Isofarro
    Jun 28, 2003
  2. Edwin Dankert
    Replies:
    7
    Views:
    475
    Peter Flynn
    Oct 6, 2007
  3. Edwin Dankert
    Replies:
    0
    Views:
    404
    Edwin Dankert
    Jan 23, 2008
  4. Abby Lee
    Replies:
    5
    Views:
    436
    Abby Lee
    Aug 2, 2004
  5. Replies:
    0
    Views:
    140
Loading...

Share This Page