0% found this document useful (0 votes)
23 views7 pages

CS 2205-01 Web Programming 1 Unit 7

Uploaded by

millanongt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views7 pages

CS 2205-01 Web Programming 1 Unit 7

Uploaded by

millanongt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

XML Schema (XSD)

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="[Link]

<xs:element name="catalog">

<xs:complexType>

<xs:sequence>

<xs:element name="book" maxOccurs="unbounded">

<xs:complexType>

<xs:sequence>

<xs:element name="title" type="xs:string"/>

<xs:element name="publicationYear" type="xs:integer"/>

<xs:element name="author">

<xs:complexType>

<xs:sequence>

<xs:element name="firstName" type="xs:string"/>

<xs:element name="lastName" type="xs:string"/>

</xs:sequence>

</xs:complexType>
</xs:element>

</xs:sequence>

<xs:attribute name="id" type="xs:string" use="required"/>

<xs:attribute name="available" type="xs:boolean" use="required"/>

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

JSON Data Structure

"books": [

"title": "The Great Gatsby",

"author": {

"firstName": "F. Scott",

"lastName": "Fitzgerald"
},

"publicationYear": 1925,

"details": {

"publisher": "Charles Scribner's Sons",

"pageCount": 218

},

"available": true

},

"title": "To Kill a Mockingbird",

"author": {

"firstName": "Harper",

"lastName": "Lee"

},

"publicationYear": 1960,

"details": {

"publisher": "J.B. Lippincott & Co.",

"pageCount": 281
},

"available": true

},

"title": "1984",

"author": {

"firstName": "George",

"lastName": "Orwell"

},

"publicationYear": 1949,

"details": {

"publisher": "Secker & Warburg",

"pageCount": 328

},

"available": false

}
Importance of XML Namespaces

XML namespaces are crucial for managing the bookstore's data by preventing naming conflicts

when integrating data from multiple sources, such as supplier catalogs or customer reviews.

They allow unique identification of elements and attributes using a URI, ensuring clarity in

complex documents. For instance, declaring a namespace with

xmlns:bookstore="[Link] in the XML document avoids conflicts

if another system uses a "title" element differently. This is particularly useful when merging data

from external vendors or adding custom metadata (e.g., discount tags) without overlap. The

syntax involves adding a namespace declaration to the root element, like <catalog

xmlns:bookstore="[Link] and prefixing elements (e.g.,

<bookstore:title>). This ensures scalability and maintainability in the bookstore's XML-based

data management.

Comparison of XML and JSON

XML and JSON both serve the bookstore's data interchange needs, but they differ in strengths

and weaknesses. XML, with its robust XSD validation, excels in complex hierarchical data and

strict formatting, making it ideal for detailed catalog storage or integration with legacy systems.

However, its verbosity can slow parsing. JSON, being lightweight and human-readable, is better

for quick client-server data exchange, such as real-time availability updates, though it lacks

native validation. Parsing XML requires DOM or SAX in languages like JavaScript (Frisbie,

2019), while JSON's native support (Joseph & S, 2018) simplifies manipulation. The bookstore
might use XML for structured data exports to partners and JSON for API responses, leveraging

each format's strengths based on the use case.


References:

Joseph, D. B., & S, S. S. (2018). JavaScript and Json Essentials. Packt Publishing.

Frisbie, M. (2019). Professional JavaScript for web developers. John Wiley & Sons.

You might also like