XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 3rd, 2012, 04:06 AM
Xperia124 Xperia124 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 3 Xperia124 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 55 m 6 sec
Reputation Power: 0
Help with XML, HTML

Hi everyone,

I am really new to XML and HTTP and I am trying to write a code compatible to browsers such as Firefox, Chrome and Safari. The HTML is to search an XML file looking for an specific value (inputted time). Once that is found, all consecutive entries are stored and displayed in a table. So far this is what I achieved however I am having trouble making it work. Any help/advice/comment would be very much appreciated.

Thank you!

Carl.


XML File: (data.xml)

Code:

<?xml version="1.0"?>


<SYSTEM_FY>


<ST
  ST="12:59:00" VAL="149.99">
</ST>

<ST
  ST="12:59:15" VAL="200">
</ST>

<ST
  ST="12:59:30" VAL="149.958">
</ST>

<ST
  ST="12:59:45" VAL="250">
</ST>

<ST
  ST="13:00:00" VAL="149.962">
</ST>

<ST
  ST="13:00:15" VAL="149">
</ST>

<ST
  ST="13:00:30" VAL="150.024">
</ST>

</SYSTEM_FY>




HTML file (searchfy.html):

Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>Search</title>
<script type="text/javascript">


window.onload = loadIndex;

function loadIndex() {

    if (window.XMLHttpRequest)
            {
             xmlDoc=new XMLHttpRequest();
            }
        else
            {
             xmlDoc=new ActiveXobject("Microsoft.XMLHTTP");
            }
         xmlDoc.open("GET",data.xml,false);
         xmlDoc.send();
         return xmlDoc.responseXML;
        }



function searchIndex() { // search the index
   
        loadIndex();
   
    var searchterm = document.getElementById("searchme").value;
    var allitems = xmlDoc.getElementsByTagName("ST");
        results = new Array;
    if (searchterm.length < 6) {
        alert("Incorrect input");
    }
    else {
// see if the XML entry matches the search term in first loop then once term is found, all consecutive entries are stored in the array to be displayed later
// and (if so) store it in an array        \
        for (var i=0;i<allitems.length;i++) {
            var x = allitems[i];
            var exp = new RegExp(searchterm,"i");
            if ( x.match(exp) != null) {
                for(var j=i;j<allitems.length;j++){
                                       results.push(allitems[j]);
                                       }
            }
        }
// send the results to another function that displays them to the user
    showResults(results);
    }
}



// Write search results to a table
function showResults(results) {

    if (results.length > 0) {
// if there are any results, write them to a table
       
        document.write('<div><a href="searchfy.html">New Search</a></div><br><br>');
        document.write('<table border="1" style="width: 100%;">');
        document.write('<tr><th>ST</th><th>VAL</th></tr>');
        for(var k=0; k<results.length; k++) {
         document.write('<tr>');
         document.write('<td>' + results[k].getAttribute("ST") + '</td>');
         document.write('<td>' + results[k].getAttribute("VAL") + '</td>');
         document.write('</tr>');
        }
        document.write('<table>');
        document.close();
       
       
    } else {
// else tell the user no matches were found
        var notfound = alert('No results found for '+searchterm+'!');
    }
}
</script>

</head><body>
<form name="frmMain" id="frmMain" action="">
<b>Search:&nbsp;&nbsp;</b>

<input id="searchme" type="text" size="20">&nbsp;&nbsp;<br><br>
<input value="Submit (e.g: 12:59:00 or 13:00:00)" onclick="searchIndex(); return false;" type="submit">
</form>

</body>
</html>

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Help with XML, HTML

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap