SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member bakri's Avatar
    Join Date
    Apr 2006
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question help... search in multiple xml files... TipueJS

    I will talk about the Script Tipue Js...

    it's very good search engine with rss and xml....

    and the problem with xml version

    i have no problem with this script but...

    But what i want search in multiple xml files ....

    i made a small edit in the .js file and it is..

    Code:
    xml_data = ["file1.xml", "file2.xml"]; 
    
    for (var c = 0; c < xml_data.length; c++) { 
    
    if (data_source < 2) 
    { 
       var s = new Array(); 
       if (window.ActiveXObject) 
       { 
          var xmldoc = new ActiveXObject("Microsoft.XMLDOM"); 
          xmldoc.async = false; 
          xmldoc.onreadystatechange = function() 
          { 
             if (xmldoc.readyState == 4) get_xml(); 
          } 
       } 
       else if (document.implementation && document.implementation.createDocument) 
       { 
          var xmldoc = document.implementation.createDocument("", "", null); 
          xmldoc.async = false; 
          xmldoc.onload = get_xml; 
    
       } 
       xmldoc.load(xml_data[c]); 
    } 
    }


    this is the code what i made ...

    there is a problem

    the code just read the last file !... why ??!

    why it only read one file

    help me please

    Best Regards

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Correct, you run through the loop x number of times and each time you load an xml file - overwriting the previous one you loaded.

    You have a few options:
    - load each xml file, do the search, return the results, move to next xml file
    - load 5 xml files into one big mishmash of xml.

    I suspect option 2 will work better for you, so here's some sample code:
    Code:
    function createDOM() {
    	var xmldoc;
    	if (window.ActiveXObject) 
    	{ 
    	  xmldoc = new ActiveXObject("Microsoft.XMLDOM"); 
    	  xmldoc.async = false; 
    	  xmldoc.onreadystatechange = function() 
    	  { 
    	     if (xmldoc.readyState == 4) get_xml(); 
    	  } 
    	} 
    	else if (document.implementation && document.implementation.createDocument) 
    	{ 
    	  xmldoc = document.implementation.createDocument("", "", null); 
    	  xmldoc.async = false; 
    	  xmldoc.onload = get_xml; 
    	
    	} 
    	return xmldoc;	
    }
    
    var xml_data = ["file1.xml", "file2.xml"]; 
    var mishmash = createDOM();
    var mishmashroot = mishmash.appendChild(mishmash.createElement("theroot"));
    
    for (var c = 0; c < xml_data.length; c++) { 
    	if (data_source < 2) 
    	{ 
    	   var s = new Array();
    	   var xmldoc = createDOM();
    	   xmldoc.load(xml_data[c]);
    	   mishmashroot.appendChild(xmldoc.firstChild);
    	}
    }
    
    // do stuff with mishmash


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •