XML File and XSD of the file Solution – 39298

XML File and XSD of the file

Initial Task

BookingRef CustomerName FlightID DepartureDate SeatBooked Fare
BM308Z John Citizen QF237 231014 24D $127.95
DM709A Lucy QD334 240914 22A $111.85
FR432B Andy Bar ER432 241014 21E $231.88
TR443E Ashton VC332 251014 22R $111.95
QW221R Mike RF554Q 231014 13D $123.33
BG213E Nancy TG522J 291014 12J $156.88

 

XSD of the file

<xs:schema attributeFormDefault=”unqualified” elementFormDefault=”qualified” xmlns:xs=”http://www.w3.org/2001/XMLSchema”>

<xs:element name=”Booked”>

<xs:complexType>

<xs:sequence>

<xs:element name=”Booking” maxOccurs=”unbounded” minOccurs=”0″>

<xs:complexType>

<xs:sequence>

<xs:element type=”xs:string” name=”BookingRef”/>

<xs:element type=”xs:string” name=”CustomerName”/>

<xs:element type=”xs:string” name=”FlightID”/>

<xs:element type=”xs:int” name=”DepartureDate”/>

<xs:element type=”xs:string” name=”SeatBooked”/>

<xs:element type=”xs:float” name=”Fare”/>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

 

XML File

<?xml version=”1.0″ encoding=”UTF-8″ standalone=”yes”?>

<Booked>

<Booking>

     <BookingRef>BM308Z</BookingRef>

     <CustomerName>John Citizen</CustomerName>

     <FlightID>QF237</FlightID>

     <DepartureDate>231014</DepartureDate>

     <SeatBooked>24D</SeatBooked>

     <Fare>127.95</Fare>

</Booking>

<Booking>

     <BookingRef>DM709A</BookingRef>

     <CustomerName>Lucy</CustomerName>

     <FlightID>QD334</FlightID>

     <DepartureDate>240914</DepartureDate>

     <SeatBooked>22A</SeatBooked>

     <Fare>111.85</Fare>

</Booking>

<Booking>

     <BookingRef>FR432B</BookingRef>

     <CustomerName>Andy Bar</CustomerName>

     <FlightID>ER432</FlightID>

     <DepartureDate>241014</DepartureDate>

     <SeatBooked>21E</SeatBooked>

     <Fare>231.88</Fare>

</Booking>

<Booking>

     <BookingRef>TR443E</BookingRef>

     <CustomerName>Ashton</CustomerName>

     <FlightID>VC332</FlightID>

     <DepartureDate>251014</DepartureDate>

     <SeatBooked>22R</SeatBooked>

     <Fare>111.95</Fare>

</Booking>

<Booking>

     <BookingRef>QW221R</BookingRef>

     <CustomerName>Mike</CustomerName>

     <FlightID>RF554Q</FlightID>

     <DepartureDate>231014</DepartureDate>

     <SeatBooked>13D</SeatBooked>

     <Fare>123.33</Fare>

</Booking>

<Booking>

     <BookingRef>BG213E</BookingRef>

     <CustomerName>Nancy</CustomerName>

     <FlightID>TG522J</FlightID>

     <DepartureDate>291014</DepartureDate>

     <SeatBooked>12J</SeatBooked>

     <Fare>156.88</Fare>

</Booking>

</Booked>

XSL file to show data in descending of fare

<html xsl:version=”1.0″

xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”

lang=”en”>

<head>

<title>Sales Results By Division</title>

</head>

<body>

<table border=”1″>

<tr>

<th>Booking</th>

<th>Customer Name</th>

<th>Flight ID</th>

<th>Departure Date</th>

<th>Seat Booked</th>

<th>Fare</th>

 

</tr>

<xsl:for-each select=”Booked/Booking”>

<xsl:sort select=”Fare”

order=”descending”/>

<tr>

<td><xsl:value-of select=”BookingRef”/></td>

<td><xsl:value-of select=”CustomerName”/></td>

<td><xsl:value-of select=”FlightID”/></td>

<td><xsl:value-of select=”DepartureDate”/></td>

<td><xsl:value-of select=”SeatBooked”/></td>

<td><xsl:value-of select=”Fare”/></td>

</tr>

</xsl:for-each>

</table>

</body>

</html>

 

 

 

DOM file to load the XML Data

<!DOCTYPE html>

<html>

<head>

<script src=”loadxmldoc.js”></script>

</head>

<body>

<script>

xmlDoc=loadXMLDoc(“book.xml”);

x=xmlDoc.getElementsByTagName(‘Booking’);

for (i=0;i<x.length;i++)

{

document.write(x[i].childNodes[0].nodeValue);

document.write(“<br>”);

}

</script>

</body>

</html>

This will show all the booking data of the xml document

 

Manipulating the value of the first record

<!DOCTYPE html>

<html>

<head>

<script src=”loadxmldoc.js”></script>

</head>

<body>

 

<script>

 

xmlDoc=loadXMLDoc(“book.xml”);

 

x=xmlDoc.getElementsByTagName(“SeatBooked”)[0]

y=x.childNodes[0];

document.write(y.nodeValue); //this will print the value

x.childNodes[0] = 25Z

document.write(y.nodeValue); //this will print the modified value

 

</script>

</body>

</html>