how do i search xml data using javascript?

Hi. Basically I have a text box and and button. I would put a text on the text box and when I press the button, I want it to search for that word in my xml file. It would then be displayed in the same page.

My problem is that I’m only able to search for elements/nodes but not the text itself. My javascript is able to load the xml file. I’ve been searching online for a few days and I can’t find anything. Please help, thank you


Related posts:

  1. How do you search for a specific XML feed?
  2. Is there any way to force Google (or any other MAJOR search engine) to return an XML file as search results?
  3. How to load xml file using radio button?

One Response to “how do i search xml data using javascript?”

  • Arnab Dutta:

    You does not mention that u want to search for your word within XML document’s elements or nodes.

    I have a sample code which can search your input text within XML doc elements….

    **************XML DOC************
    <employees>
    <employee id="5">John Doe</employee>
    <employee id="6">Arnab</employee>
    </employees>
    *************************************
    try //Internet Explorer
    {
    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    }
    catch(e)
    {
    try //Firefox, Mozilla, Opera, etc.
    {
    xmlDoc=document.implementation.createDocument("","",null);
    }
    catch(e)
    {
    alert(e.message);

    }
    }
    xmlDoc.async=false;
    xmlDoc.load("note.xml");
    alert(xmlDoc.text.search("Arnab"));
    // search function return -1 if the value is not found else it will return index of the search key within the XML

Leave a Reply