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)

    Lightbulb problem with load xml files

    hi all,
    how u doing??!

    it's K

    i got this script collect data and search in it from xml file

    the xml file is data.xml:
    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <data>
    	<get>
    		<name>david</name>
    		<num>123</num>
    		<city>London</city>
    	</get>	
    	<get>
    		<name>John</name>
    		<num>549</num>
    		<city>Kent</city>
    	</get>	
    </data>
    and in the javascript file name.js:
    Code:
    ....
    .....
    var xml_data = 'data.xml';
    ....
    ....
    
    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);
    }
    is this case the script work very good... but ...

    But if i want resive data from more than one file
    file 1: data1.xml
    file 2: data2.xml
    file 3: data3.xml

    example:
    Code:
    var xml_data = new Array()
    xml_data[0] =  'data1.xml';
    xml_data[0] =  'data2.xml';
    xml_data[0] =  'data3.xml';
    how the javascript script code will be ??!
    i mean what is the code to load more than xml file ?

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    xmlFiles = ["file1.xml", "file2.xml"];
    
    function readXML(file_) {
    xmldoc = file_;
    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);
    }
    }
    
    alert(xmlFiles.forEach(readXML));
    cheers


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
  •