XML is a markup language that defines rules for encoding documents to be both human- and machine-readable. It allows users to define customized tagging structures for different types of documents. A DTD defines the structure and legal elements and attributes of an XML document, ensuring documents conform to the specified rules. XML documents can reference internal or external DTDs to validate document structure. Elements, attributes, and other syntax rules like closing tags help ensure XML documents are properly structured and readable.
XML Introduction,Syntax of XML,Well formed XML Documents,XML Document Structure,Document Type Definitions,XML Namespace,XML Schemas,DOM(Document Object Model)
Myassignmenthelp.net has a team of experts competent to handle all kinds of computer network assignments and homework. We are capable of handling all kinds of homework and assignments. Our team of dedicated experts has a rich experience of working with top-tier software firms across the world and understand all the aspects of a programming language http://www.myassignmenthelp.net/programming-assignment-help.php
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
XML Introduction,Syntax of XML,Well formed XML Documents,XML Document Structure,Document Type Definitions,XML Namespace,XML Schemas,DOM(Document Object Model)
Myassignmenthelp.net has a team of experts competent to handle all kinds of computer network assignments and homework. We are capable of handling all kinds of homework and assignments. Our team of dedicated experts has a rich experience of working with top-tier software firms across the world and understand all the aspects of a programming language http://www.myassignmenthelp.net/programming-assignment-help.php
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
Honest Reviews of Tim Han LMA Course Program.pptxtimhan337
Personal development courses are widely available today, with each one promising life-changing outcomes. Tim Han’s Life Mastery Achievers (LMA) Course has drawn a lot of interest. In addition to offering my frank assessment of Success Insider’s LMA Course, this piece examines the course’s effects via a variety of Tim Han LMA course reviews and Success Insider comments.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
1. 1
XML-Introduction
What is XML?
• XML stands for eXtensible Markup Language
• It is a text-based markup language derived from
Standard Generalized Markup Language (SGML).
• XML was designed to store and transport data
• XML was designed to be self-descriptive
• XML is a markup language that defines set of rules for
encoding documents in a format that is both human-
readable and machine-readable.
• XML is a W3C Recommendation
2. 2
• These document reference a Document Type Definition
(DTD) or schema, which defines the structure for the
document .
• Markup is information added to a document that
enhances its meaning in certain ways, in that it identifies
the parts and how they relate to each other.
• More specifically, a markup language is a set of symbols
that can be placed in the text of a document and label the
parts of that document
XML-Introduction
3. XML
• It is a method for putting structured data into a text file;
these files are
• - easy to read
• - unambiguous
• - extensible
• - platform-independent
• XML documents are used to transfer data from one
place to another often over the Internet.
April 29th, 2003 Organizing and Searching Information with XML 3
4. 4
XML
XML is a meta markup language
for text documents / textual data
XML allows to define languages
(„applications“) to represent text
documents / textual data
5. 5
XML Does Not DO Anything
<note>
<to> SAM</to>
<from> JOHN</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
The XML above is quite self-descriptive:
It has sender, receiver information
It has a heading and a message body.
6. XML
• XML can work behind the scene to simplify the creation
of HTML documents for large web sites
• XML can be used to exchange the information between
organizations and systems
• XML can easily be merged with style sheets to create
almost any desired output.
April 29th, 2003 Organizing and Searching Information with XML 6
7. Differences between XML and HTML
HTML XML
HTML tags have a fixed
meaning and browsers know
what it is
XML tags are different for
different applications, and
users know what they mean
HTML tags are used for
display.
XML tags are used to
describe documents and data
Tags and attributes are
predetermined
allows user to specify what
each tag and attribute means
April 29th, 2003 Organizing and Searching Information with XML 7
8. 8
Differences between XML and HTML
HTML XML
content and formatting can
be placed together
content and format are
separate; formatting is
contained in a stylesheet
Designed to represent the
presentation structure of a
document
Designed to represent the
logical structure of a
document
HTML was designed to
display data - with focus on
how data looks
XML was designed to carry
data - with focus on what
data is
9. 9
XML
• XML is Extensible
Most XML applications will work as
expected even if new data is added
• XML Simplifies Things
It simplifies data sharing
It simplifies data transport
It simplifies platform changes
It simplifies data availability
10. 10
XML-Uses
• XML is used in many aspects of web
development.
• XML is often used to separate data from
presentation.
• Web searching and automating Web tasks
• e-business applications
12. XML-uses
• 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.
April 29th, 2003 Organizing and Searching Information with XML 12
15. XML Syntax Rules
• XML Declaration
• The XML document can optionally have an XML
declaration. It is written as below:
• <?xml version="1.0" encoding="UTF-8"?>
Syntax Rules for XML declaration
The XML declaration is case sensitive and must begin with
"<?xml>" where "xml" is written in lower-case.
If document contains XML declaration, then it strictly needs to be
the first statement of the XML document
April 29th, 2003 Organizing and Searching Information with XML 15
16. XML Syntax Rules
• Tags and Elements
• An XML file is structured by several XML-elements,
also called XML-nodes .
• XML-elements' names are enclosed by angular brackets
< > as shown below:
• <element-name>
• Syntax Rules for Tags and Elements
• Element Syntax: <element> text </element>
April 29th, 2003 Organizing and Searching Information with XML 16
17. XML Syntax Rules
• Root element:
An XML document can have only one root element.
Case sensitivity:
The names of XML-elements are case-sensitive.
The name of the start and the end elements need to
be exactly in the same case.
April 29th, 2003 Organizing and Searching Information with XML 17
18. XML Syntax Rules
• Attributes
An attribute specifies a single property for the element,
using a name/value pair
XML References
References usually allow you to add or include additional
text or markup in an XML document.
References always begin with the symbol "&" ,which is a
reserved character and end with the symbol ";".
XML has two types of references:
April 29th, 2003 Organizing and Searching Information with XML 18
19. • Entity References: An entity reference contains a name
between the start and the end delimiters.
• For example & where amp is name..
• Character References: These contain references, such
as A, contains a hash mark (“#”) followed by a
number.
• The number always refers to the Unicode code of a
character. In this case, 65 refers to alphabet "A".
April 29th, 2003 Organizing and Searching Information with XML 19
20. 20
Entity References
Some characters have a special meaning in XML.
<message>salary < 1000</message>
This will generate an XML error:
To avoid this error, replace the "<" character with an
entity reference:
<message>salary < 1000</message>
23. XML-Syntax Rules
• All XML Elements Must Have a Closing Tag
• XML Tags are Case Sensitive
• XML Elements Must be Properly Nested
• XML Attribute Values Must Always be Quoted
23
24. • Comments in XML
• The syntax for writing comments in XML is similar to
that of HTML:
• <!-- This is a comment -->
24
25. Defining XML Tags
• XML tags form the foundation of XML.
• They define the scope of an element in
XML.
• They can also be used to declare settings
required for parsing the environment, and to
insert special instructions.
25
26. Defining XML Tags
• Start Tag
• The beginning of every non-empty XML element is
marked by a start-tag. Example of start-tag −
<address>
• End Tag
• Every element that has a start tag should end with an
end-tag. Following is an example of end-tag −
</address>
26
27. Defining XML Tags
• Empty Tag
• The text that appears between start-tag and end-tag is
called content.
• An element which has no content is termed as empty.
An empty element can be represented in two ways as
follows −
• A start-tag immediately followed by an end-tag as
shown below −
• <hr></hr>
• A complete empty-element tag is as shown below −
• <hr />
27
28. Defining XML Tags
• XML Tags Rules
• Rule 1
• XML tags are case-sensitive.
• Invalid Tag
• <address>This is wrong syntax</Address>
• Valid Tag
• <address>This is correct syntax</address>
28
29. Defining XML Tags
• Rule 2
• XML tags must be closed in an appropriate order,
i.e., an XML tag opened inside another element
must be closed before the outer element is closed.
For example −
• <outer_element>
• <internal_element>
• This tag is closed before the outer_element
</internal_element>
• </outer_element>
29
30. XML Elements
• An XML element is everything from (including) the
element's start tag to (including) the element's end tag.
• <price>29.99</price>
• An element can contain:
• text
• attributes
• other elements
• or a mix of the above
30
31. XML Elements
• Empty Element
• An element with no content is said to be empty.
• In XML, you can indicate an empty element like this:
• <element></element>
• Empty elements can have attributes.
31
32. XML Naming Rules
• XML elements must follow these naming rules:
• Element names are case-sensitive
• Element names must start with a letter or underscore
• Element names cannot start with the letters xml (or
XML, or Xml, etc)
• Element names can contain letters, digits, hyphens,
underscores, and periods
• Element names cannot contain spaces
• Any name can be used, no words are reserved (except
xml).
32
33. XML Attributes
• Attributes are part of XML elements.
• An element can have multiple unique
attributes. Attribute gives more information
about XML elements.
• Attributes they define properties of elements.
• An XML attribute is always a name-value
pair.
33
34. XML Attributes
• XML Attributes Must be Quoted
• Attribute values must always be quoted. Either
single or double quotes can be used.
• An XML attribute has the following syntax −
• <element-name attribute1 attribute2 >
....content..
• </element-name>
<book publisher="Tata McGraw Hill"></book>
34
35. Element Attribute Rules
• An attribute name must not appear more
than once in the same start-tag or empty-
element tag.
• An attribute must be declared in the
Document Type Definition (DTD) using an
Attribute-List Declaration.
35
36. Document Type Definition.
• A DTD is a Document Type Definition.
• A DTD defines the structure and the legal
elements and attributes of an XML document.
• The XML Document Type Declaration,
commonly known as DTD, is a way to describe
XML language precisely.
• DTDs check vocabulary and validity of the
structure of XML documents against
grammatical rules of appropriate XML
language.
36
37. DTD
• Syntax
• Basic syntax of a DTD is as follows −
• <!DOCTYPE element DTD identifier
• [ declaration1
• declaration2
• ........ ]>
37
38. DTD
• The DTD starts with <!DOCTYPE delimiter.
• An element tells the parser to parse the document from
the specified root element.
• DTD identifier is an identifier for the document type
definition, which may be the path to a file on the system
or URL to a file on the internet.
38
39. Internal DTD
• Internal DTD
• A DTD is referred to as an internal DTD if elements are
declared within the XML files.
• Syntax
• Following is the syntax of internal DTD −
• <!DOCTYPE root-element [element-declarations]>
where root-element is the name of root element and
element-declarations is where you declare the elements.
39
40. Internal DTD
• <?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
</note>
40
41. Internal DTD
• !DOCTYPE note defines that the root element of this document
is note
• !ELEMENT note defines that the note element must contain four
elements: "to,from,heading,body"
• !ELEMENT to defines the to element to be of type "#PCDATA"
• !ELEMENT from defines the from element to be of type
"#PCDATA"
• !ELEMENT heading defines the heading element to be of type
"#PCDATA"
• !ELEMENT body defines the body element to be of type
"#PCDATA"
41
42. DTD
• Rules
• The document type declaration must appear at
the start of the document (preceded only by the
XML header) - it is not permitted anywhere else
within the document.
• Similar to the DOCTYPE declaration, the
element declarations must start with an
exclamation mark.
• The Name in the document type declaration must
match the element type of the root element.
42
43. External DTD
• In external DTD elements are declared
outside the XML file.
• They are accessed by specifying the system
attributes which may be either the legal .dtd
file or a valid URL.
• To reference it as external DTD, standalone
attribute in the XML declaration must be set
as no. This means, declaration includes
information from the external source.
43
44. External DTD
• Syntax
• Following is the syntax for external DTD −
• <!DOCTYPE root-element SYSTEM "file-name">
where file-name is the file with .dtd extension.
• Example
• The following example shows external DTD usage
44
47. External DTD
• Types
• Refer an external DTD by either using system
identifiers or public identifiers.
• System Identifiers
• A system identifier enables to specify the
location of an external file containing DTD
declarations. Syntax is as follows −
• <!DOCTYPE name SYSTEM "address.dtd" [...]>
47
48. External DTD
• Public Identifiers
• Public identifiers provide a mechanism to locate DTD
resources and are written as below −
• <!DOCTYPE name PUBLIC "-//Beginning
XML//DTD Address Example//EN">
• Public identifiers are used to identify an entry in a
catalog.
• Public identifiers follows, a commonly used format
called Formal Public Identifiers, or FPIs.
48
49. XML-DTD
• DTD-Element Declarations
• XML elements can be defined as building blocks of an
XML document.
• Elements can behave as a container to hold text,
elements, attributes, media objects or mix of all.
• In a DTD, XML elements are declared with the
following syntax:
• <!ELEMENT element-name type>
or
<!ELEMENT element-name (element-content)>
April 29th, 2003 Organizing and Searching Information with XML 49
50. XML-DTD
• Value of type can be ANY or EMPTY
• Content can be data or another element
Elements are classified as
• Standalone elements- also called Singleton elements
or empty elements-- they are empty.
• <!ELEMENT element-name EMPTY>
• Ex: <!ELEMENT br EMPTY>
• In xml file <br />
April 29th, 2003 Organizing and Searching Information with XML 50
51. XML-DTD
• Simple elements
These are the elements that contain text or Parsed Character Data
( represented as #PCDATA)
<!ELEMENT element-name (#PCDATA) >
Ex: <!ELEMENT greeting (#PCDATA) >
In xml: <greeting>Welcome to XML </greeting>
April 29th, 2003 Organizing and Searching Information with XML 51
52. XML-DTD
• Compound Elements- This elements can contain other
elements. An element contains one element.
• <!ELEMENT element-name (child-element-name)>
EX: <!ELEMENT employee (name)>
Xml : <employee>
<name> ABC </name>
</employee>
April 29th, 2003 Organizing and Searching Information with XML 52
53. XML-DTD
• Occurrence Indicators
• <!ELEMENT employee (contact*)>
• <!ELEMENT company (employee+)>
• <!ELEMENT book (author+)>
• <!ELEMENT employee (PAN?)>
April 29th, 2003 Organizing and Searching Information with XML 53
54. XML-DTD
Declaring Multiple Children
<!ELEMENT element-name (child1,child2,child3)>
EX:
<!ELEMENT employee (name,dept,id)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT dept (#PCDATA)>
<!ELEMENT id (#PCDATA)>
April 29th, 2003 Organizing and Searching Information with XML 54
55. XML-DTD
• Sequence operator( , )
• <!ELEMENT employee (name , dept, id)>
• Choice Operator ( | )
• <!ELEMENT product (price | discountprice )>
• Composite Operator [ ( ) ]
• <!ELEMENT biodata ( dob , ( company,title)* )>
April 29th, 2003 Organizing and Searching Information with XML 55
56. XML DTD elements
Mixed content example
<?xml version = "1.0" encoding = "UTF-8" standalone = "yes" ?>
<!DOCTYPE address [
<!ELEMENT address (#PCDATA | name)* >→ mixed content
<!ELEMENT name (#PCDATA)>
]>
<address>
Here's a bit of text mixed up with the child element.
<name>
Tanmay Patil
</name>
</address>
April 29th, 2003 Organizing and Searching Information with XML 56
57. Attribute Declarations
• Attribute Declaration
• Attributes are used to associate(name , value) pairs with elements.
• They are useful to provide useful information about the element’s
content.
• Syntax:
• <!ATTLIST element-name attribute-name
attribute-type default-value >
DTD example: <!ELEMENT payment EMPTY>
• <!ATTLIST payment type CDATA "check">
XML example: <payment type="check" />
April 29th, 2003 Organizing and Searching Information with XML 57
58. April 29th, 2003 Organizing and Searching Information with XML 58
64. Entity Declaration
• Entities are variables that represent other values.
• If a text contains entities, the value of the entity is substituted by
its actual value when ever the text is parsed.
• Entities may be parsed or unparsed.
Two types of Entity declarations
• GENERAL ENTITY-They are used with in the document
content
• PARAMETER ENTITY-They are parsed entities for use with
in the DTD.
April 29th, 2003 Organizing and Searching Information with XML 64
67. Entity Declaration
• Parameter Entity Declaration
It allows us to assign a collection of elements, attributes and attribute
values to a name and refer them using a name instead of listing them
every time they are used.
Parameter-Entity Declaration
• <!ENTITY % entity-name entity-def>
• Example : <!ENTITY % info “year , make, model”>
DTD: <!ELEMENT car (% info;) >
➔ <!ELEMENT car (year , make, model)>
April 29th, 2003 Organizing and Searching Information with XML 67
68. XML Schema
• XML Schema is commonly known as XML Schema
Definition (XSD).
• A more powerful way of defining the structure and
constraining the contents of XML documents .
• It is used to describe and validate the structure and
the content of XML data.
• XML schema defines the elements, attributes and
data types.
• Supports Namespaces
• It is similar to a database schema that describes the data
in a database.
April 29th, 2003 Organizing and Searching Information with XML 68
69. XML Schema
• XML Schema is an XML-based alternative to DTD.
• XML Schemas Support Data Types
• It is easier to describe document content
• It is easier to define restrictions on data
• It is easier to validate the correctness of data
• It is easier to convert data between different data types
69
71. XML Schema
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="values" type="xs:string" />
</xs:schema>
April 29th, 2003 Organizing and Searching Information with XML 71
72. XML Schema
<?xml version = "1.0"?>
< xs:schema
xmlns:xs = "http://www.w3.org/2001/XMLSchema"
targetNamespace = "http://www.xmldata.com"
xmlns = "http://www.xmldata.com" >
April 29th, 2003 Organizing and Searching Information with XML 72
73. XML Schema
<xs:schema
xmlns:xs = "http://www.w3.org/2001/XMLSchema">
The above fragment specifies that elements and datatypes
used in the schema are defined in
http://www.w3.org/2001/XMLSchema namespace
and these elements/data types should be prefixed with xs
April 29th, 2003 Organizing and Searching Information with XML 73
74. • targetNamespace = http://www.xmldata.com
The above fragment specifies that elements used in this
schema are defined in http://www.xmldata.com
namespace. It is optional.
xmlns = http://www.xmldata.com
April 29th, 2003 Organizing and Searching Information with XML 74
75. XML Schemas
• <?xml version = "1.0" encoding = "UTF-8"?>
<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema">
75
76. XML Schema
• Defining XML Elements in Schema
• An element can be defined within an XSD as follows:
<xs:element name="x" type="y" />
April 29th, 2003 Organizing and Searching Information with XML 76
77. XML Schema
• The valid data values for the element in the XML
document can be further constrained using the fixed and
default properties.
• Default means that if no value is specified in the XML
document then the application reading the document,
typically an XML parser or XML Data Binding Library,
should use the default specified in the XSD.
• Fixed means the value in the XML document can only
have the value specified in the XSD.
April 29th, 2003 Organizing and Searching Information with XML 77
79. XML schema
• Specifying Element Cardinality
• It is possible to constrain the number of instances
(cardinality) of an XML element that appear in an XML
document.
• The cardinality is specified using the minOccurs and
maxOccurs attributes, and allows an element to be
specified as mandatory, optional, or can appear up to a
set number of times.
• The default values for minOccurs and maxOccurs is 1
April 29th, 2003 Organizing and Searching Information with XML 79
81. XML schema
Element Definition Types
Simple Type
• Simple type element is used only in the context of the
text. Some of the predefined simple types are:
xs:integer, xs:boolean, xs:string, xs:date. example −
• <xs:element name = "phone_number" type = "xs:integer" />
• <xs:element name="Customer_dob" type="xs:date" />
• <xs:element name="Customer_address" type="xs:string" />
April 29th, 2003 Organizing and Searching Information with XML 81
82. XML schema
• Complex Type
• A complex type is a container for other element
definitions.
• This allows you to specify which child elements an
element can contain and to provide some structure
within XML documents.
• Complex Element is an XML element which can contain
other elements and/or attributes
April 29th, 2003 Organizing and Searching Information with XML 82
83. XML schema
• Example --Complex Type
April 29th, 2003 Organizing and Searching Information with XML 83
84. XML schema
• Defining Compositors
• Compositors provide rules that determine how and in what order
there children can appear within XML document.
• There are three types of compositors
• <xs:sequence>,
• <xs:choice>
• <xs:all>
April 29th, 2003 Organizing and Searching Information with XML 84
86. XML Schemas
• Global Complex Types
• A xs:complexType can also defined globally and given a
name.
• Named xs:complexTypes can then be re-used throughout
the schema, either referenced directly or used as the
basis to define other xs:complexTypes.
86
89. XML Schemas
• Attributes
• Attributes in XSD provide extra information
within an element. Attributes have name and type
property as shown below −
• <xs:attribute name = "x" type = "y"/>
• An Attribute can appear 0 or 1 times within
a given element in the XML document.
Attributes are either optional or mandatory
89
90. XML Schemas
<xs:attribute name="ID" type="xs:string" />
<xs:attribute name="ID" type="xs:string" use="optional" />
Example:
<xs:element name="Order">
<xs:complexType>
<xs:attribute name="OrderID" type="xs:int" />
</xs:complexType>
</xs:element>
April 29th, 2003 Organizing and Searching Information with XML 90
91. XML Schemas
• XML Element Mixed Content
April 29th, 2003 Organizing and Searching Information with XML 91
92. XML Schemas
• XML Schemas are More Powerful than DTD
• XML Schemas are written in XML
• XML Schemas are extensible to additions
• XML Schemas support data types
• With XML Schema, your XML files can carry a
description of its own format.
• With XML Schema, independent groups of people can
agree on a standard for interchanging data.
• With XML Schema, you can verify data.
92
93. DOCUMENT OBJECT MODEL(DOM)
• The Document Object Model (DOM) is a W3C
standard.
• It defines a standard for accessing documents like
HTML and XML.
• The Document Object Model (DOM) is an
application programming interface (API) for
HTML and XML documents.
• It defines the logical structure of documents and
the way a document is accessed and manipulated.
93
94. DOCUMENT OBJECT MODEL(DOM)
• DOM defines the objects and properties and
methods (interface) to access all XML elements.
• It is separated into 3 different parts / levels −
• Core DOM − standard model for any structured
document
• XML DOM − standard model for XML
documents
• HTML DOM − standard model for HTML
documents
94
95. DOCUMENT OBJECT MODEL (DOM)
• XML DOM is a standard object model for XML.
XML documents have a hierarchy of
informational units called nodes;
• DOM is a standard programming interface of
describing those nodes and the relationships
between them.
• The XML DOM makes a tree-structure view for
an XML document.
95
96. DOCUMENT OBJECT MODEL
• Following is the diagram for the DOM structure.
The diagram depicts that parser evaluates an
XML document as a DOM structure by
traversing through each node.
96
98. DOCUMENT OBJECT MODEL
• Advantages of XML DOM
• The following are the advantages of XML DOM.
• XML DOM is language and platform independent.
• XML DOM is traversable - Information in XML DOM
is organized in a hierarchy which allows developer to
navigate around the hierarchy looking for specific
information.
• XML DOM is modifiable - It is dynamic in nature
providing the developer a scope to add, edit, move or
remove nodes at any point on the tree.
April 29th, 2003 Organizing and Searching Information with XML 98
99. DOCUMENT OBJECT MODEL
• Disadvantages of XML DOM
• It consumes more memory (if the XML structure is
large) as program written once remains in memory all
the time until and unless removed explicitly.
• Due to the extensive usage of memory, its operational
speed, compared to SAX is slower.
April 29th, 2003 Organizing and Searching Information with XML 99
100. XML-DOCUMENT OBJECT MODEL
XML DOM Properties
These are some typical DOM properties:
• x.nodeName - the name of x
• x.nodeValue - the value of x
• x.parentNode - the parent node of x
• x.childNodes - the child nodes of x
• x.attributes - the attributes nodes of x
• Note: In the list above, x is a node object.
April 29th, 2003 Organizing and Searching Information with XML 100
101. XML-DOCUMENT OBJECT MODEL
• XML DOM Methods
• x.getElementsByTagName(name) - get all
elements with a specified tag name
• x.appendChild(node) - insert a child node to x
• x.removeChild(node) - remove a child node from
x
• Note: In the list above, x is a node object.
April 29th, 2003 Organizing and Searching Information with XML 101
102. XML-DOCUMENT OBJECT MODEL
• An example to show how an XML document
("note.xml") is parsed into an XML DOM object.
• This example parses an XML document
(note.xml) into an XML DOM object and
extracts information from it with JavaScript.
April 29th, 2003 Organizing and Searching Information with XML 102
103. XML-DOCUMENT OBJECT MODEL
• <?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>john@starone.com</to>
<from>vimal@yahoo.com</from>
<body>Hello XML DOM</body>
</note>
April 29th, 2003 Organizing and Searching Information with XML 103
104. XML-DOM
• <!DOCTYPE html>
• <html>
• <body>
• <h1>Important Note</h1>
• <b>To:</b> <span id="to"></span><br>
• <b>From:</b> <span id="from"></span><br>
• <b>Message:</b> <span id="message"></span>
•
April 29th, 2003 Organizing and Searching Information with XML 104
105. XML-DOM
<script>
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{ // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"
);
}
April 29th, 2003 Organizing and Searching Information with XML 105
109. XHTML
• XHTML stands for EXtensible HyperText Markup
Language.
• XHTML was developed by World Wide Web
Consortium (W3C) to help web developers make the
transition from HTML to XML
• XHTML is almost identical to HTML XHTML is
stricter than HTML
April 29th, 2003 Organizing and Searching Information with XML 109
110. XHTML
Important Differences from HTML:
XHTML DOCTYPE is mandatory
The xmlns attribute in <html> is mandatory
<html>, <head>, <title>, and <body> are mandatory
XHTML Elements
XHTML elements must be properly nested
XHTML elements must always be closed
XHTML elements must be in lowercase
XHTML documents must have one root element
April 29th, 2003 Organizing and Searching Information with XML 110
111. XHTML
XHTML Attributes
Attribute names must be in lower case
Attribute values must be quoted
Attribute minimization is forbidden
April 29th, 2003 Organizing and Searching Information with XML 111
112. • <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0 Transitional//EN”
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title of document</title>
</head>
<body>
some content
</body>
</html>
April 29th, 2003 Organizing and Searching Information with XML 112
113. USES OF XHTML
• XHTML documents are XML conforming as they are
readily viewed, edited, and validated with standard
XML tools.
• XHTML documents can be written to operate better than
they did before in existing browsers as well as in new
browsers.
• XHTML documents can utilize applications such as
scripts and applets that rely upon either the HTML
Document Object Model or the XML Document Object
Model.
• XHTML gives you a more consistent, well-structured
format so that your webpages can be easily parsed and
processed by present and future web browsers.
April 29th, 2003 Organizing and Searching Information with XML 113
114. XHTML
• The XHTML standard defines three Document Type
Definitions (DTDs). The most commonly used and easy
one is the XHTML Transitional document.
• XHTML 1.0 document type definitions correspond to
three DTDs −
• Strict
• Transitional
• Frameset
April 29th, 2003 Organizing and Searching Information with XML 114
115. XHTML
• XHTML 1.0 Strict
• If you are planning to use Cascading Style Sheet (CSS)
strictly and avoiding to write most of the XHTML
attributes, then it is recommended to use this DTD
• XHTML 1.0 Transitional
• If you are planning to use many XHTML attributes as
well as few Cascading Style Sheet properties, then
you should adopt this DTD and you should write your
XHTML document accordingly.
April 29th, 2003 Organizing and Searching Information with XML 115
116. XHTML
• <!DOCTYPE html PUBLIC "-//W3C//DTD
XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-
strict.dtd">
April 29th, 2003 Organizing and Searching Information with XML 116
117. April 29th, 2003 Organizing and Searching Information with XML 117
118. April 29th, 2003 Organizing and Searching Information with XML 118
119. April 29th, 2003 Organizing and Searching Information with XML 119
120. DOM Parser in JAVA
• DOM is part of the Java API for XML processing
(JAXP).
• Java DOM parser traverses the XML file and
creates the corresponding DOM objects.
• These DOM objects are linked together in a tree
structure.
• The parser reads the whole XML structure into
the memory.
April 29th, 2003 Organizing and Searching Information with XML 120
121. DOM Parser in JAVA
DOM interfaces
• The DOM defines several Java interfaces
• Node − The base datatype of the DOM.
• Element − The vast majority of the objects you'll
deal with are Elements.
• Attr − Represents an attribute of an element.
• Text − The actual content of an Element or Attr.
• Document − Represents the entire XML
document. A Document object is often referred to
as a DOM tree.
April 29th, 2003 Organizing and Searching Information with XML 121
122. • Document.getDocumentElement() − Returns the root
element of the document.
• Node.getFirstChild() − Returns the first child of a
given Node.
• Node.getLastChild() − Returns the last child of a given
Node.
• Node.getNextSibling() − These methods return the next
sibling of a given Node.
• Node.getPreviousSibling() − These methods return the
previous sibling of a given Node.
• Node.getAttribute(attrName) − For a given Node, it
returns the attribute with the requested name.
April 29th, 2003 Organizing and Searching Information with XML 122
DOM Methods
123. USING DOM in JAVA
• Steps to Using JDOM
• Following are the steps used while parsing a document
using JDOM Parser.
• Import XML-related packages.
• Create a DocumentBuilder.
• Create a Document from a file or stream
• Extract the root element
• Examine attributes
• Examine sub-elements
April 29th, 2003 Organizing and Searching Information with XML 123
124. Using DOM in JAVA
• Import XML-related packages
• import org.w3c.dom.*;
• import javax.xml.parsers.*;
• import java.io.*;
• Create a DocumentBuilder
• DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder =
factory.newDocumentBuilder();
April 29th, 2003 Organizing and Searching Information with XML 124
125. Using DOM in java
• Create a Document from a file
• File inputFile = new File("input.xml");
• Document doc = builder.parse(inputFile);
• Extract the root element
• Element root = document.getDocumentElement();
Examine attributes
• //returns specific attribute
• getAttribute("attributeName");
• //returns a Map (table) of names/values
• getAttributes();
April 29th, 2003 Organizing and Searching Information with XML 125
126. Using DOM in java
• Examine sub-elements
• //returns a list of subelements of specified name
getElementsByTagName("subelementName");
• //returns a list of all child nodes
• getChildNodes();
April 29th, 2003 Organizing and Searching Information with XML 126
127. Using DOM in java
• <?xml version = "1.0"?>
• <class>
• <student rollno = "393">
<firstname>dinkar</firstname>
• <marks>85</marks> </student>
• <student rollno = "493">
<firstname>Vaneet</firstname>
<marks>95</marks> </student>
• </class>
127
128. April 29th, 2003 Organizing and Searching Information with XML 128
129. April 29th, 2003 Organizing and Searching Information with XML 129
130. April 29th, 2003 Organizing and Searching Information with XML 130
131. SAX Parser
• SAX Stands for Simple API for XML Parsing.
This is an event based XML Parsing and it parse
XML file line by line so much suitable for large
XML Files.
• SAX XML Parser fires an event when it
encountered opening tag, element or attribute,
and the parsing works accordingly.
April 29th, 2003 Organizing and Searching Information with XML 131
132. SAX Parser
• Use SAX XML parser for parsing large XML files in
Java because it doesn't require to load whole XML file
in Java and it can read a big XML file in small parts. J
• Java provides support for SAX parser and you can parse
any XML file in Java using SAX Parser
• One disadvantage of using SAX Parser in java is that
reading XML file in Java using SAX Parser requires
more code in comparison of DOM Parser.
Read more:
April 29th, 2003 Organizing and Searching Information with XML 132
133. SAX Parser in jAVA
• The callback methods of DefaultHandler class:-
• startDocument() – This method called at the start of the
XML document.
• endDocument() – This method called at the end of the
XML document.
• startElement() – This method called at the start of a
document element.
• endElement() – This method called at the end of a
document element.
• characters() – This method called with the text contents
in between the start and end tags of an XML document
element.
April 29th, 2003 Organizing and Searching Information with XML 133