470,874 Members | 1,769 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Share your developer knowledge by writing an article on Bytes.

XML from Start to Finish - Phase 1

Dököll
2,364 Expert 2GB
Hey gang!

I thought this may be of use. Pretty old project from College, the code is familiar, but just in case someone is looking.

Program: Apartment Search Database
Language: HTML, XML, XSL, CSS, JavaScript


(1) Save the below in an XML file called apartmentlist.xmlThis file is linked with web pages in the Apartment Search Database. Be sure to save as .xml, Save as Type: All Files.


Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0"?>
  3. <!-- File Name: apartmentlist.xml -->
  4.  
  5. <?xml-stylesheet type="text/xsl" href="ApartmentSearch.xsl"?>
  6.  
  7. <RENTALUNITS>
  8.    <LISTING>
  9.       <APARTMENT>Konner Ridge</APARTMENT>
  10.       <ADDRESS>23 Monroe St.</ADDRESS>
  11.       <PHONE>256-5533</PHONE>
  12.       <BEDROOMS>3</BEDROOMS>
  13.       <BATHS>2</BATHS>
  14.       <VACANCY>2</VACANCY>
  15.    </LISTING>
  16.    <LISTING>
  17.       <APARTMENT>Konner Ridge</APARTMENT>
  18.       <ADDRESS>23 Monroe St.</ADDRESS>
  19.       <PHONE>256-5533</PHONE>
  20.       <BEDROOMS>1</BEDROOMS>
  21.       <BATHS>1</BATHS>
  22.       <VACANCY>2</VACANCY>
  23.    </LISTING>
  24.    <LISTING>
  25.       <APARTMENT>River Side Apartments</APARTMENT>
  26.       <ADDRESS>400 St. Joe River Rd.</ADDRESS>
  27.       <PHONE>395-4474</PHONE>
  28.       <BEDROOMS>1</BEDROOMS>
  29.       <BATHS>1</BATHS>
  30.       <VACANCY>2</VACANCY>
  31.    </LISTING>
  32.    <LISTING>
  33.       <APARTMENT>White Oak Apartments</APARTMENT>
  34.       <ADDRESS>900 W. 111th St</ADDRESS>
  35.       <PHONE>398-4123</PHONE>
  36.       <BEDROOMS>2</BEDROOMS>
  37.       <BATHS>2</BATHS>
  38.       <VACANCY>1</VACANCY>
  39.    </LISTING>
  40.    <LISTING>
  41.       <APARTMENT>Moore Woods Apartments</APARTMENT>
  42.       <ADDRESS>200 N. 1st St.</ADDRESS>
  43.       <PHONE>695-0695</PHONE>
  44.       <BEDROOMS>2</BEDROOMS>
  45.       <BATHS>1</BATHS>
  46.       <VACANCY>2</VACANCY>
  47.    </LISTING>
  48.    <LISTING>
  49.       <APARTMENT>Rhodes Manner Apartments</APARTMENT>
  50.       <ADDRESS>1000 Welsh Ave</ADDRESS>
  51.       <PHONE>395-3305</PHONE>
  52.       <BEDROOMS>4</BEDROOMS>
  53.       <BATHS>2</BATHS>
  54.       <VACANCY>2</VACANCY>
  55.    </LISTING>
  56. </RENTALUNITS>
  57.  
  58.  
(2) Save this one as another XML file, name it App_Price.xml
Stick it in a folder called BEDS. This file is linked with web pages in the Apartment Search Database. Be sure to save as .xml, Save as Type: All Files.


Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0"?>
  3. <!-- File Name: App_Price.xml -->
  4. <Find_It>
  5.     <Apartmnt>
  6.        <Name>Konner Ridge</Name>
  7.        <Type>Condominium</Type>
  8.        <Crime-Rate_1>13 % Low</Crime-Rate_1>
  9.        <Crime-Rate_2>26 % High</Crime-Rate_2>    
  10.        <Your_Price>$189,000.00</Your_Price>
  11.     </Apartmnt>
  12.  
  13.  
  14.     <Apartmnt>
  15.        <Name>Konner Ridge III</Name>
  16.        <Type>Apartment Building</Type>
  17.        <Crime-Rate_1>23 % Low</Crime-Rate_1>
  18.        <Crime-Rate_2>35 % High</Crime-Rate_2>
  19.        <Your_Price>$89,000.00</Your_Price>
  20.     </Apartmnt>
  21.  
  22.  
  23.     <Apartmnt>
  24.        <Name>Konner Ridge VI</Name>
  25.        <Type>1600 Brick House</Type>
  26.        <Crime-Rate_1>10 % Low</Crime-Rate_1>
  27.        <Crime-Rate_2>12 % High</Crime-Rate_2>
  28.      <Your_Price>$1,600,000.00</Your_Price>
  29.     </Apartmnt>
  30.  
  31.  
  32.     <Apartmnt>
  33.        <Name>Eastwood Place Apartments</Name>
  34.        <Type>Brick Mansion</Type>
  35.        <Crime-Rate_1>9 % Low</Crime-Rate_1>
  36.        <Crime-Rate_2>12 % High</Crime-Rate_2>
  37.        <Your_Price>$590,000.00</Your_Price>
  38.     </Apartmnt>
  39.  
  40.  
  41.     <Apartmnt>
  42.        <Name>Blair House</Name>
  43.        <Type>Condominium</Type>
  44.        <Crime-Rate_1>5 % Low</Crime-Rate_1>
  45.        <Crime-Rate_2>10 % High</Crime-Rate_2>
  46.        <Your_Price>$2,021,899.00</Your_Price>
  47.     </Apartmnt>
  48.  
  49.  
  50.     <Apartmnt>
  51.        <Name>Blair House IV</Name>
  52.        <Type>Old Brick House</Type>
  53.        <Crime-Rate_1>3 % Low</Crime-Rate_1>
  54.        <Crime-Rate_2>8 % High</Crime-Rate_2>
  55.        <Your_Price>$678,000.00</Your_Price>
  56.     </Apartmnt>
  57.  
  58.  
  59.  
  60.     <Apartmnt>   
  61.        <Name>Vorhaus Condos</Name>
  62.        <Type>Condominium</Type>
  63.        <Crime-Rate_1>11 % Low</Crime-Rate_1>
  64.        <Crime-Rate_2>16 % High</Crime-Rate_2>       
  65.        <Your_Price>$1,189,000.00</Your_Price>
  66.     </Apartmnt>
  67. <Apartmnt>
  68.        <Name>The French Quarter</Name>
  69.        <Type>Condominium</Type>
  70.        <Crime-Rate_1>3 % Low</Crime-Rate_1>
  71.        <Crime-Rate_2>6 % High</Crime-Rate_2>      
  72.        <Your_Price>$699,670.00</Your_Price>
  73.   </Apartmnt>
  74.  
  75. </Find_It>
  76.  
  77.  
(3) Add the XSL file, must be named ApartmentSearch.xslThis file is linked with web pages in the Apartment Search Database. Be sure to save as .xsl, Save as Type: All Files.


Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0"?>
  3. <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  4.    <xsl:template match="/">
  5.  Database search     
  6. <center>
  7.       <a href="Uhome.html"><img border="0" src="4433444.bmp" alt="Click here to go home"></img></a>
  8.       <h2>Browse Availability</h2>
  9.       </center>
  10.       <xsl:for-each select="RENTALUNITS/LISTING">
  11.       <xsl:sort select="APARTMENT" />
  12.         <p>
  13.           <span style="font-style:italic; font-weight: 900; color: #ff6633">
  14.              <xsl:value-of select="ADDRESS" />
  15.           </span>
  16.           <xsl:text> </xsl:text>
  17.           <span style="font-variant:small-caps; font-weight:bold">
  18.              <xsl:value-of select="PHONE"/>
  19.           </span>
  20.         </p>
  21.         <p style="margin-left: 3%">
  22.           <span style="font-weight:bold">Number of Bedrooms/Baths </span>
  23.           <xsl:value-of select="BEDROOMS" /> bedrooms and <xsl:value-of select="BATHS"/> baths. 
  24.           Number of vacancies:
  25.           <span style="font-style:italic; font-weight: bold; color:#009999">
  26.               <xsl:value-of select="VACANCY" />
  27.           </span>
  28.         </p> 
  29.       </xsl:for-each>
  30.    </xsl:template>
  31. </xsl:transform>
  32.  
  33.  
(4) Add a couple of HTML files, this one should be named apartment.htmlThis file is linked with web pages in the Apartment Search Database. Be sure to save as .html, Save as Type: All Files.


Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head>
  6. <title>Fetch Bedrooms</title>
  7. </head>
  8. <body bgcolor="gray">
  9. <xml id="dsoRENTALUNITS" src="BEDS/App_Price.xml"></xml>
  10. <p align="center">
  11. <a href="index.htm"><img border="0" src="img_citywide.gif"></img></a></p>
  12. <p></p>
  13. <p style="font-size:24px; color: #332266; font-weight:900">Search By # of Rooms</p>
  14. <p style="font-size:18px; color: white; font-weight:100">Number of Rooms:<input type="text" id="searchtext" size="20" onKeyPress="keyPressed()">&nbsp;
  15. <button onClick="findApp()">search</button>
  16. </p>
  17.  
  18.  
  19. <hr size="5" color="#cccccc"/>
  20. <div id="searchresult">
  21.  <p style="font-size:18px; color: lime; font-weight:100">Results:
  22. </div>
  23. <script type="text/javascript">
  24. <!--hide from old browsers
  25. function keyPressed(k) {
  26.    var hitEnter=event.keyCode
  27.    if (hitEnter==13) findApp()
  28.    }
  29.  
  30. function findApp() {
  31.    searchstring = searchtext.value.toUpperCase()
  32.    if (searchstring=="") {
  33.       searchresult.innerHTML = "<b>Please add # of rooms in textbox.</b>"
  34.       return
  35.    }
  36.    dsoRENTALUNITS.recordset.moveFirst()
  37.    var outputresult=""
  38.    while (!dsoRENTALUNITS.recordset.EOF) {
  39.       namestring = dsoRENTALUNITS.recordset("Num_Bed").value
  40.       if (namestring.toUpperCase().indexOf(searchstring)>=0)
  41.          outputresult += "<b>" + dsoRENTALUNITS.recordset("Num_Bed")+"</b> ("+dsoRENTALUNITS.recordset("Beds")+")</p>"
  42.                       + "<p style='margin-left:25px'><b>Location: </b>"+dsoRENTALUNITS.recordset("Local")+"</p>"
  43.                       + "<p style='margin-left:25px'><b>For: </b>"
  44.                       + dsoRENTALUNITS.recordset("Option_Bound") +"<br /></p>"
  45.          dsoRENTALUNITS.recordset.moveNext()
  46.    }
  47.       if (outputresult=="")
  48.          searchresult.innerHTML = "Number of rooms selected currently unavailable."
  49.       else
  50.          searchresult.innerHTML = outputresult
  51. }
  52. //-->           
  53. </script>
  54.  
  55. <hr size="5" color="#cccccc" />
  56.  
  57. <br>
  58.   <table align="center" width="670">
  59.   <tr>
  60.      <td width="34%">
  61.         <a href="apartmentlist.xml">Browse Location</a>
  62.      </td>
  63.      <td width="34%">
  64.         <a href="apartment_price.html">Browse Price</a> 
  65.      </td>
  66.      <td width="32%">
  67.         <a href="apartment.html">Search Rooms</a>
  68.      </td>
  69.   </tr>
  70. </table>
  71. </center>
  72.  
  73. <br>
  74. <br>
  75.  
  76. <p>
  77. <b><CENTER>
  78. <FONT FACE="Arial" SIZE="-2" color="white">
  79. Copyright &copy;  2006-2008 For more information about our business,<br> please contact us: <a href="mailto:XXXXXXX@Me.org"><FONT FACE="Arial" SIZE="-2" color="lightgreen"><b>XXXXXXX@Me.org</a></b></font><br> All rights reserved.
  80. <br></CENTER>
  81. </p>
  82. </FONT></b>
  83. </body>
  84. </html>
  85.  
  86.  

(5) Name below, apartment_price.htmlThis file is linked with web pages in the Apartment Search Database. Be sure to save as .html, Save as Type: All Files.


Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <xml id="dsoApp" src="App_Price.xml"></xml>
  6. <head>
  7.    <title>Browse By Price</title>
  8. </head>
  9. <body bgcolor="gray">
  10. <center>
  11. <a href="index.html"><img border="0" src="img_citywide.gif"></img></a> 
  12. <h2>Apartment Listing By Price</h2>
  13. <button onclick="AppTable.firstPage()">|&lt; First Page </button>&nbsp;&nbsp;
  14. <button onclick="AppTable.previousPage()">&lt; Previous Page </button>&nbsp;&nbsp;
  15. <button onclick="AppTable.nextPage()"> Next Page &gt; </button>&nbsp;&nbsp;
  16. <button onclick="AppTable.lastPage()"> Last Page &gt;| </button>
  17. <hr color="#666666" size="5" width="75%" />
  18. <table id="AppTable" datasrc="#dsoApp" datapagesize="6" border="1" cellpadding="5">
  19.    <thead style="color:darkred; font-size:14pt; font-weight:900">
  20.       <th>TYPE</th>
  21.       <th>NAME</th>
  22.       <th>CRIME RATE</th>
  23.       <th>YOUR PRICE</th>
  24.    </thead>     
  25.    <tr>
  26.        <td><span datafld="Type" style="font-family:arial; font-style:italic"></span></td>
  27.        <td><span datafld="Name" style="font-family:arial; font-weight:900"></span></td>
  28.        <td><span datafld="Crime-Rate_1"></span>, <span datafld="Crime-Rate_2"></span></td>
  29.        <td><span datafld="Your_Price"></span></td>
  30.    </tr>
  31. </table>
  32.  
  33. <br>
  34.   <table align="center" width="670">
  35.   <tr>
  36.      <td width="34%">
  37.         <a href="apartmentlist.xml">Browse Location</a>
  38.      </td>
  39.      <td width="34%">
  40.         <a href="apartment_price.html">Browse Price</a> 
  41.      </td>
  42.      <td width="32%">
  43.         <a href="apartment.html">Search Bedrooms</a>
  44.      </td>
  45.   </tr>
  46. </table>
  47. </center>
  48. <p>
  49. <b><CENTER>
  50. <FONT FACE="Arial" SIZE="-2" color="white">
  51. Copyright &copy;  2006-2008 For more information about our business,<br> please contact us: <a href="mailto:XXXXXXX@You.org"><FONT FACE="Arial" SIZE="-2" color="lightgreen"><b>XXXXXXX@You.org</a></b></font><br> All rights reserved.
  52. <br></CENTER>
  53. </p>
  54. </FONT></b>
  55. </body>
  56. </html>
  57.  
  58.  

(6) Here is our index.htmlThis file is linked with web pages in the Apartment Search Database. Be sure to save as .html, Save as Type: All Files.


Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head>
  6. <title>XXXXX, Inc.  Apartment Search</title>
  7. </head>
  8. <body bgcolor="gray">
  9. <table border="0" width="90%">
  10.   <tr>
  11.     <td><div align="center"><p style="font-weight:bold"><center>Welcome our home Page! <br><img src="7666646.gif" /></div>
  12. </tr></td>
  13. </table>
  14. <table border="0" width="90%">
  15. <tr>
  16.         <td align="center" width="26%"><img src="ttttetetetet.jpg" usemap="#DatabaseSearchbar"/>
  17.     <map name="DatabaseSearchbar">
  18.       <area shape="rect" coords="16,90,195,117" href="apartmentlist.xml" alt="Browse Location" />   
  19.       <area shape="rect" coords="39,131,167,157" href="apartment_price.html" alt="Browse Price" />
  20.       <area shape="rect" coords="35,169,173,195" href="apartment.html" alt="Search Bedrooms" />
  21.     </map>
  22.     </td>
  23.   </tr>
  24. </table>
  25.  
  26. <br>
  27.   <table align="center" width="670">
  28.   <tr>
  29.      <td width="34%">
  30.         <a href="apartmentlist.xml">Browse Location</a>
  31.      </td>
  32.      <td width="34%">
  33.         <a href="apartment_price.html">Browse Price</a> 
  34.      </td>
  35.      <td width="32%">
  36.         <a href="apartment.html">Search Bedrooms</a>
  37.      </td>
  38.   </tr>
  39. </table>
  40.  
  41. <p>
  42. <b><CENTER>
  43. <FONT FACE="Arial" SIZE="-2" color="white">
  44. Copyright &copy;  2006-2008 For more information about our business,<br> please contact us: <a href="mailto:XXXXXXX@You.org"><FONT FACE="Arial" SIZE="-2" color="lightgreen"><b>XXXXXXX@You.org</a></b></font><br> All rights reserved.
  45. <br></CENTER>
  46. </p>
  47. </FONT></b>
  48. </body>
  49. </html>
  50.  
Please note: XML Data in this web site were managed through a variety of platforms. An ASP.NET web site allowed data to be added to an SQL Server 2005 database, which were then loaded to an Access Database. A VB application helped make up XML files to load to the above.

Related link: http://bytes.com/forum/thread762010.html

Added info: http://bytes.com/forum/thread777267.html

Have fun!

Dököll
Jul 4 '07 #1
3 7636
Hey,

I did all this but no data shows up in the listing by price page and the data is all just text in the browse by location page and the search by # of bedrooms doesnt return any results.

Is this info coming in phase 2 or something?
Jan 28 '08 #2
Dököll
2,364 Expert 2GB
Hey there!


This is a complete code. A working one in fact used in a live web site....

You may be having problems with the JavaScript portion. Please compare both your code and the posted on. Will look to see if anything's amiss. And sorry for the inconvenience.

In a bit!
Jan 29 '08 #3
Dököll
2,364 Expert 2GB
Hey there good buddy!

Here is the complete app, download and save the files to the same location, put App_Price file in a folder called BEDS.

apartment.htm
apartment_price.htm
ApartmentSearch.xsl
App_Price.xml
apartmentlist.xml
index.htm

Download, then scan for viruses before opening if you're not comfortable.

Hope this works for ya...

Dököll
Sep 19 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Anonieko Ramos | last post: by
2 posts views Thread by Mark | last post: by
29 posts views Thread by Stefan Slapeta | last post: by
13 posts views Thread by paul.joseph.davis | last post: by
1 post views Thread by Craig Coope | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.