Xml
20
.xsd
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="university"> <xs:complexType> <xs:sequence> <xs:element name="department" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="course" maxOccurs="unbounded" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
xml<?xml version="1.0" encoding="UTF-8"?> <university xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="university.xsd"> <department> <name>kiran</name> <course>Introduction to Programming</course> <course>Data Structures</course> </department> <department> <name>Arun</name> <course>Calculus I</course> <course>Linear Algebra</course> </department> </university>
19Xsl<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h2>Students Personal Details</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Name</th> <th>Age</th> <th>DOB</th> <th>Mobile</th> <th>Address</th> </tr> <xsl:for-each select="students/student"> <tr> <td><xsl:value-of select="name"/></td> <td><xsl:value-of select="age"/></td> <td><xsl:value-of select="dob"/></td> <td><xsl:value-of select="mobile"/></td> <td><xsl:value-of select="address"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>Xml<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="students.xsl"?> <students> <student> <name>Aswath S</name> <age>21</age> <dob>09/08/2000</dob> <mobile>912345674</mobile> <address>CBE</address> </student> <student> <name>Surya M</name> <age>21</age> <dob>04/08/2000</dob> <mobile>998765439</mobile> <address>CBE</address> </student> </students>21jsfunction loadXMLData() { // Create a new XMLHttpRequest object var xhr = new XMLHttpRequest(); // Open the request to fetch the XML file xhr.open("GET", "web.xml", true); // Replace "web.xml" with the path or URL of your XML file // Set up a function to handle the response xhr.onload = function() { if (xhr.status === 200) { // Parse the XML string into an XML document var xmlDoc = xhr.responseXML; // Call a function to display the data displayXMLData(xmlDoc); } else { console.error("Failed to load XML data."); } }; // Send the request xhr.send(); } function displayXMLData(xmlDoc) { // Get the container to display the data var container = document.getElementById("data-container"); // Clear any existing data in the container container.innerHTML = ""; // Get all items from the XML data (assuming you are looking for <item> elements) var items = xmlDoc.getElementsByTagName("item"); // Loop through each <item> and display its data for (var i = 0; i < items.length; i++) { var item = items[i]; // Extract data from the XML element (change based on your XML structure) var title = item.getElementsByTagName("title")[0].textContent; var description = item.getElementsByTagName("description")[0].textContent; // Create HTML content dynamically using template literals (backticks) var div = document.createElement("div"); div.classList.add("item"); // Use template literals for string interpolation div.innerHTML = `<h3>${title}</h3><p>${description}</p>`; // Append the div to the container container.appendChild(div); } }Xml<?xml version="1.0" encoding="UTF-8"?> <items> <item> <title>Item 1</title> <description>This is the description for item 1.</description> </item> <item> <title>Item 2</title> <description>This is the description for item 2.</description> </item> <item> <title>Item 3</title> <description>This is the description for item 3.</description> </item> </items>22Xml<?xml version="1.0" encoding="UTF-8"?> <catalog> <book> <title>The Great Gatsby</title> <author>F. Scott Fitzgerald</author> <price>10.99</price> <description>A classic novel about the American dream, set in the 1920s.</description> </book> <book> <title>1984</title> <author>George Orwell</author> <price>8.99</price> <description>A dystopian novel exploring government surveillance and totalitarianism.</description> </book> <book> <title>To Kill a Mockingbird</title> <author>Harper Lee</author> <price>12.49</price> <description>A story of racial injustice in the American South, told through the eyes of a young girl.</description> </book> <book> <title>The Catcher in the Rye</title> <author>J.D. Salinger</author> <price>9.99</price> <description>A novel about a troubled teenager's journey through New York City.</description> </book> <book> <title>Brave New World</title> <author>Aldous Huxley</author> <price>11.49</price> <description>A dystopian society that has achieved "utopia" through technology and genetic engineering.</description> </book> </catalog>
Comments
Post a Comment