SlideShare a Scribd company logo
1 of 27
An XML file is a file used to store data in the form of
hierarchical elements. Data stored in XML files can be read by
computer programs with the help of custom tags, which
indicate the type of element. Since XML files are plain text
documents, they are easy to create, store, transport, and
interpret by computers and humans alike. This is why XML is
one of the most commonly used languages on the internet.
Many web-based software applications store information and
send information to other apps in XML format.
XML Separates Data from Presentation
• XML does not carry any information about how to be
displayed.
• The same XML data can be used in many different
presentation scenarios.
• Because of this, with XML, there is a full separation between
data and presentation.
In many HTML applications, XML is used to store or transport
data, while HTML is used to format and display the same data.
XML Separates Data from HTML
• When displaying data in HTML, you should not have to edit
the HTML file when the data changes.
• With XML, the data can be stored in separate XML files.
• With a few lines of JavaScript code, you can read an XML file
and update the data content of any HTML page.
XML Does Not Use Predefined Tags
The XML language has no predefined tags.
The tags in the example above (like <to> and <from>) are not
defined in any XML standard. These tags are "invented" by the
author of the XML document.
HTML works with predefined tags like <p>, <h1>, <table>, etc.
With XML, the author must define both the tags and the
document structure.
XML is Extensible
Most XML applications will work as expected even if new data
is added (or removed).
Imagine an application designed to display the original version
of note.xml (<to> <from> <heading> <body>).
Then imagine a newer version of note.xml with added <date>
and <hour> elements, and a removed <heading>.
Uses of XML
XML has a variety of uses for Web, e-business, and portable applications.
The following are some of the many applications for which XML is useful:
Web publishing: XML allows you to create interactive pages, allows the
customer to customize those pages, and makes creating e-commerce
applications more intuitive. With XML, you store the data once and then
render that content for different viewers or devices based on style sheet
processing using an Extensible Style Language (XSL)/XSL Transformation
(XSLT) processor.
Web searching and automating Web tasks: XML defines the type of
information contained in a document, making it easier to return useful
results when searching the Web:For example, using HTML to search for
books authored by Tom Brown is likely to return instances of the term
'brown' outside of the context of author. Using XML restricts the search to
the correct context (for example, the information contained in the <author>
tag) and returns only the information that you want. By using XML, Web
agents and robots (programs that automate Web searches or other tasks)
are more efficient and produce more useful results.
General applications: XML provides a standard method to
access information, making it easier for applications and
devices of all kinds to use, store, transmit, and display data.
e-business applications: XML implementations make
electronic data interchange (EDI) more accessible for
information interchange, business-to-business
transactions, and business-to-consumer transactions.
Metadata applications: XML makes it easier to express
metadata in a portable, reusable format.
Pervasive computing: XML provides portable and
structured information types for display on pervasive
(wireless) computing devices such as personal digital
assistants (PDAs), cellular phones, and others. For example,
WML (Wireless Markup Language) and VoiceXML are
currently evolving standards for describing visual and
speech-driven wireless device interfaces.
Thousands of XML formats exist, in many different industries, to
describe day-to-day data transactions:
• Stocks and Shares
• Financial transactions
• Medical data
• Mathematical data
• Scientific measurements
• News information
• Weather services
Transaction Data
• Open your text editor of choice.
• On the first line, write an XML declaration.
• Set your root element below the declaration.
• Add your child elements within the root element.
• Review your file for errors.
• Save your file with the .xml file extension.
• Test your file by opening it in the browser window.
How to Create an XML File
Every XML file has one root element, which contains all other
child elements. The root element is written below the
declaration.
XML Tree
The XML Tree Structure
XML documents must contain one root element that is the parent of all
other elements
The XML prolog is optional. If it exists, it must come first in the document.
An element can contain:
text
attributes
other elements
or a mix of the above
Attribute values
must always be
quoted. Either
single or double
quotes can be
used.
In the first example, gender is an attribute. In the last example, gender is an
element. Both examples provide the same information.
XML Namespaces provide a method to avoid element name conflicts.
In XML, element names are defined by the developer. This often results in a conflict
when trying to mix XML documents from different XML applications.
XML Namespaces
What is an XML Schema?
An XML Schema describes the structure of an XML document.
The XML Schema language is also referred to as XML Schema
Definition (XSD).
It is used to describe and validate the structure and the content of
XML data. XML schema defines the elements, attributes and data
types. Schema element supports Namespaces. It is similar to a
database schema that describes the data in a database.
The purpose of an XML Schema is to define the legal building
blocks of an XML document:
• the elements and attributes that can appear in a document
• the number of (and order of) child elements
• data types for elements and attributes
• default and fixed values for elements and attributes
XML Schemas Support Data Types
One of the greatest strength of XML Schemas is the support for
data types.
•It is easier to describe allowable document content
•It is easier to validate the correctness of data
•It is easier to define data facets (restrictions on data)
•It is easier to define data patterns (data formats)
•It is easier to convert data between different data types
XML Schemas use XML Syntax
Another great strength about XML Schemas is that they are written
in XML.
•You don't have to learn a new language
•You can use your XML editor to edit your Schema files
•You can use your XML parser to parse your Schema files
•You can manipulate your Schema with the XML DOM
•You can transform your Schema with XSLT
XML Schemas are extensible, because they are written in XML.
XML Schemas Secure Data Communication
When sending data from a sender to a receiver, it is essential that
both parts have the same "expectations" about the content.
With XML Schemas, the sender can describe the data in a way
that the receiver will understand.
A date like: "03-11-2004" will, in some countries, be interpreted
as 3.November and in other countries as 11.March.
However, an XML element with a data type like this:
<date type="date">2004-03-11</date>
ensures a mutual understanding of the content, because the XML
data type "date" requires the format "YYYY-MM-DD".
example
XML Document:
1. XML stands for eXtensible Markup Language.
2. XML is a markup language much like HTML.
3. XML was designed to store and transport data.
4. XML was designed to carry data - with focus on
what data is.
5. HTML was designed to display data - with focus
on how data looks.
6. XML tags are not predefined like HTML tags are.
7. Extension of XML file is .xml
Example: Save file name as 'book.xml'
<?xml version="1.0" encoding="UTF-8"?>
<Book ISBN="123456789">
<Title>Sample Book</Title>
<Author>John Doe</Author>
<PublicationYear>2022</PublicationYear>
</Book>
XML schema:
1. XML schema came into the picture because of some disadvantages
in DTD(Document Type Definition)
2. DTD does not support complex type of lines of code.
3. DTD does not support more data types.
4. An XML Schema describes the structure of an XML document.
5. The XML Schema language is also called XML Schema Definition
(XSD).
6. Extension of XML schema is .xsd
7. XML supports complex types as well as data types.
8. XML schema uses XML syntax.
9. XML Schemas Secure Data Communication.
Example: Save file name as 'book_schema.xsd'
• <?xml version="1.0" encoding="UTF-8"?>
• <xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">
• <!-- Define the complex type for the Book
element -->
• <xs:element name="Book" type="BookType"/>
• <!-- Define the complex type for the Book
element's structure -->
• <xs:complexType name="BookType">
• <xs:sequence>
• <xs:element name="Title" type="xs:string"/>
• <xs:element name="Author" type="xs:string"/>
• <xs:element name="PublicationYear"
type="xs:gYear"/>
• </xs:sequence>
• <xs:attribute name="ISBN" type="xs:string"
use="required"/>
• </xs:complexType>
• </xs:schema>
Steps in Python code:
i. To execute XML schema we required library called lxml
library.
ii. To install lxml library, type command "pip install lxml" in
command prompt(CMD).
iii. Open python editor and follow below steps to validate XML
data.
1. Import the necessary library (lxml).
2. Load the XML Schema and create an XML schema validator.
3. Load the XML document and parse it.
4. Validate the XML document against the XML Schema.
5. Print the validation result or errors.
Example: Save file name as 'program_name.py'
from lxml import etree
# Load the XML Schema
schema_file = 'F:/PCET/SDL_LAB/book_schema.xsd'
schema = etree.XMLSchema(etree.parse(schema_file))
# Load the XML document
xml_file = 'F:/PCET/SDL_LAB/book.xml'
xml_doc = etree.parse(xml_file)
# Validate the XML document against the schema
if schema.validate(xml_doc):
print("Validation successful.")
else:
print("Validation failed. Errors:")
for error in schema.error_log:
print(error)
•Copy the Python code snippet into a Python script or a Jupyter notebook.
•Replace 'path/to/your/book_schema.xsd' with the actual path to your XSD file
(book_schema.xsd).
•Replace 'path/to/your/xml/book.xml' with the actual path to your XML file (book.xml).
•Run the script or cell.
•Check Validation Result (Python Only):
•If the validation is successful, you will see the message "Validation successful."
•If there are validation errors, it will print the errors.

More Related Content

Similar to XML1.pptx (20)

paper about xml
paper about xmlpaper about xml
paper about xml
 
XML Introduction
XML IntroductionXML Introduction
XML Introduction
 
XML.pptx
XML.pptxXML.pptx
XML.pptx
 
XML - Extensive Markup Language
XML - Extensive Markup LanguageXML - Extensive Markup Language
XML - Extensive Markup Language
 
What is xml
What is xmlWhat is xml
What is xml
 
Web based application of Live Scoreboard using XML.
Web based application of Live Scoreboard using XML.Web based application of Live Scoreboard using XML.
Web based application of Live Scoreboard using XML.
 
XML/XSLT
XML/XSLTXML/XSLT
XML/XSLT
 
Web programming xml
Web programming  xmlWeb programming  xml
Web programming xml
 
XML
XMLXML
XML
 
Introduction to xml
Introduction to xmlIntroduction to xml
Introduction to xml
 
Xml intro1
Xml intro1Xml intro1
Xml intro1
 
XML
XMLXML
XML
 
Xml material
Xml materialXml material
Xml material
 
Xml material
Xml materialXml material
Xml material
 
Xml material
Xml materialXml material
Xml material
 
Lecture 2 - Using XML for Many Purposes
Lecture 2 - Using XML for Many PurposesLecture 2 - Using XML for Many Purposes
Lecture 2 - Using XML for Many Purposes
 
Jaxp Xmltutorial 11 200108
Jaxp Xmltutorial 11 200108Jaxp Xmltutorial 11 200108
Jaxp Xmltutorial 11 200108
 
CTDA Workshop on XML and MODS
CTDA Workshop on XML and MODSCTDA Workshop on XML and MODS
CTDA Workshop on XML and MODS
 
Module 5 XML Notes.pdf
Module 5 XML Notes.pdfModule 5 XML Notes.pdf
Module 5 XML Notes.pdf
 
1 xml fundamentals
1 xml fundamentals1 xml fundamentals
1 xml fundamentals
 

Recently uploaded

main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIkoyaldeepu123
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 

Recently uploaded (20)

main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AI
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 

XML1.pptx

  • 1. An XML file is a file used to store data in the form of hierarchical elements. Data stored in XML files can be read by computer programs with the help of custom tags, which indicate the type of element. Since XML files are plain text documents, they are easy to create, store, transport, and interpret by computers and humans alike. This is why XML is one of the most commonly used languages on the internet. Many web-based software applications store information and send information to other apps in XML format. XML Separates Data from Presentation • XML does not carry any information about how to be displayed. • The same XML data can be used in many different presentation scenarios. • Because of this, with XML, there is a full separation between data and presentation.
  • 2. In many HTML applications, XML is used to store or transport data, while HTML is used to format and display the same data. XML Separates Data from HTML • When displaying data in HTML, you should not have to edit the HTML file when the data changes. • With XML, the data can be stored in separate XML files. • With a few lines of JavaScript code, you can read an XML file and update the data content of any HTML page.
  • 3. XML Does Not Use Predefined Tags The XML language has no predefined tags. The tags in the example above (like <to> and <from>) are not defined in any XML standard. These tags are "invented" by the author of the XML document. HTML works with predefined tags like <p>, <h1>, <table>, etc. With XML, the author must define both the tags and the document structure. XML is Extensible Most XML applications will work as expected even if new data is added (or removed). Imagine an application designed to display the original version of note.xml (<to> <from> <heading> <body>). Then imagine a newer version of note.xml with added <date> and <hour> elements, and a removed <heading>.
  • 4. Uses of XML XML has a variety of uses for Web, e-business, and portable applications. The following are some of the many applications for which XML is useful: Web publishing: XML allows you to create interactive pages, allows the customer to customize those pages, and makes creating e-commerce applications more intuitive. With XML, you store the data once and then render that content for different viewers or devices based on style sheet processing using an Extensible Style Language (XSL)/XSL Transformation (XSLT) processor. Web searching and automating Web tasks: XML defines the type of information contained in a document, making it easier to return useful results when searching the Web:For example, using HTML to search for books authored by Tom Brown is likely to return instances of the term 'brown' outside of the context of author. Using XML restricts the search to the correct context (for example, the information contained in the <author> tag) and returns only the information that you want. By using XML, Web agents and robots (programs that automate Web searches or other tasks) are more efficient and produce more useful results.
  • 5. General applications: XML provides a standard method to access information, making it easier for applications and devices of all kinds to use, store, transmit, and display data. e-business applications: XML implementations make electronic data interchange (EDI) more accessible for information interchange, business-to-business transactions, and business-to-consumer transactions. Metadata applications: XML makes it easier to express metadata in a portable, reusable format. Pervasive computing: XML provides portable and structured information types for display on pervasive (wireless) computing devices such as personal digital assistants (PDAs), cellular phones, and others. For example, WML (Wireless Markup Language) and VoiceXML are currently evolving standards for describing visual and speech-driven wireless device interfaces.
  • 6. Thousands of XML formats exist, in many different industries, to describe day-to-day data transactions: • Stocks and Shares • Financial transactions • Medical data • Mathematical data • Scientific measurements • News information • Weather services Transaction Data
  • 7. • Open your text editor of choice. • On the first line, write an XML declaration. • Set your root element below the declaration. • Add your child elements within the root element. • Review your file for errors. • Save your file with the .xml file extension. • Test your file by opening it in the browser window. How to Create an XML File Every XML file has one root element, which contains all other child elements. The root element is written below the declaration.
  • 8.
  • 9. XML Tree The XML Tree Structure XML documents must contain one root element that is the parent of all other elements
  • 10. The XML prolog is optional. If it exists, it must come first in the document. An element can contain: text attributes other elements or a mix of the above Attribute values must always be quoted. Either single or double quotes can be used.
  • 11. In the first example, gender is an attribute. In the last example, gender is an element. Both examples provide the same information.
  • 12.
  • 13.
  • 14. XML Namespaces provide a method to avoid element name conflicts. In XML, element names are defined by the developer. This often results in a conflict when trying to mix XML documents from different XML applications. XML Namespaces
  • 15. What is an XML Schema? An XML Schema describes the structure of an XML document. The XML Schema language is also referred to as XML Schema Definition (XSD). It is used to describe and validate the structure and the content of XML data. XML schema defines the elements, attributes and data types. Schema element supports Namespaces. It is similar to a database schema that describes the data in a database. The purpose of an XML Schema is to define the legal building blocks of an XML document: • the elements and attributes that can appear in a document • the number of (and order of) child elements • data types for elements and attributes • default and fixed values for elements and attributes
  • 16. XML Schemas Support Data Types One of the greatest strength of XML Schemas is the support for data types. •It is easier to describe allowable document content •It is easier to validate the correctness of data •It is easier to define data facets (restrictions on data) •It is easier to define data patterns (data formats) •It is easier to convert data between different data types XML Schemas use XML Syntax Another great strength about XML Schemas is that they are written in XML. •You don't have to learn a new language •You can use your XML editor to edit your Schema files •You can use your XML parser to parse your Schema files •You can manipulate your Schema with the XML DOM •You can transform your Schema with XSLT XML Schemas are extensible, because they are written in XML.
  • 17. XML Schemas Secure Data Communication When sending data from a sender to a receiver, it is essential that both parts have the same "expectations" about the content. With XML Schemas, the sender can describe the data in a way that the receiver will understand. A date like: "03-11-2004" will, in some countries, be interpreted as 3.November and in other countries as 11.March. However, an XML element with a data type like this: <date type="date">2004-03-11</date> ensures a mutual understanding of the content, because the XML data type "date" requires the format "YYYY-MM-DD".
  • 18.
  • 19.
  • 20.
  • 21. example XML Document: 1. XML stands for eXtensible Markup Language. 2. XML is a markup language much like HTML. 3. XML was designed to store and transport data. 4. XML was designed to carry data - with focus on what data is. 5. HTML was designed to display data - with focus on how data looks. 6. XML tags are not predefined like HTML tags are. 7. Extension of XML file is .xml
  • 22. Example: Save file name as 'book.xml' <?xml version="1.0" encoding="UTF-8"?> <Book ISBN="123456789"> <Title>Sample Book</Title> <Author>John Doe</Author> <PublicationYear>2022</PublicationYear> </Book>
  • 23. XML schema: 1. XML schema came into the picture because of some disadvantages in DTD(Document Type Definition) 2. DTD does not support complex type of lines of code. 3. DTD does not support more data types. 4. An XML Schema describes the structure of an XML document. 5. The XML Schema language is also called XML Schema Definition (XSD). 6. Extension of XML schema is .xsd 7. XML supports complex types as well as data types. 8. XML schema uses XML syntax. 9. XML Schemas Secure Data Communication.
  • 24. Example: Save file name as 'book_schema.xsd' • <?xml version="1.0" encoding="UTF-8"?> • <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> • <!-- Define the complex type for the Book element --> • <xs:element name="Book" type="BookType"/> • <!-- Define the complex type for the Book element's structure --> • <xs:complexType name="BookType"> • <xs:sequence> • <xs:element name="Title" type="xs:string"/> • <xs:element name="Author" type="xs:string"/> • <xs:element name="PublicationYear" type="xs:gYear"/> • </xs:sequence> • <xs:attribute name="ISBN" type="xs:string" use="required"/> • </xs:complexType> • </xs:schema>
  • 25. Steps in Python code: i. To execute XML schema we required library called lxml library. ii. To install lxml library, type command "pip install lxml" in command prompt(CMD). iii. Open python editor and follow below steps to validate XML data. 1. Import the necessary library (lxml). 2. Load the XML Schema and create an XML schema validator. 3. Load the XML document and parse it. 4. Validate the XML document against the XML Schema. 5. Print the validation result or errors.
  • 26. Example: Save file name as 'program_name.py' from lxml import etree # Load the XML Schema schema_file = 'F:/PCET/SDL_LAB/book_schema.xsd' schema = etree.XMLSchema(etree.parse(schema_file)) # Load the XML document xml_file = 'F:/PCET/SDL_LAB/book.xml' xml_doc = etree.parse(xml_file) # Validate the XML document against the schema if schema.validate(xml_doc): print("Validation successful.") else: print("Validation failed. Errors:") for error in schema.error_log: print(error)
  • 27. •Copy the Python code snippet into a Python script or a Jupyter notebook. •Replace 'path/to/your/book_schema.xsd' with the actual path to your XSD file (book_schema.xsd). •Replace 'path/to/your/xml/book.xml' with the actual path to your XML file (book.xml). •Run the script or cell. •Check Validation Result (Python Only): •If the validation is successful, you will see the message "Validation successful." •If there are validation errors, it will print the errors.