SlideShare a Scribd company logo
VALIDATINGAN XMLDOCUMENT
part 2
Agenda
• Validating a Document
• DTD
• Declaring Elements
• Declaring Attributes
VALIDATINGADOCUMENT
You validate documents to make certain necessary elements are never omitted.
For example, each customer order should include a customer name, address,
and phone number.
• Some elements and attributes may be optional, for example an e-mail
address.
• An XML document can be validated using either DTDs (Document Type
Definitions) or schemas.
WELL-FORMEDVS.VALID XMLDOCUMENTS
• An XML document is well-formed if it contains no syntax errors and fulfills
all of the specifications for XML code as defined by the W3C.
• An XML document is valid if it is well-formed and also satisfies the rules
laid out in the DTD or schema attached to the document.
DocumentTypeDefinitions (DTD)
• A DTD is a collection of rules or declarations that define the content and
structure of the document.
• A DTD attaches those rules to the document’s content.
• There can only be one DTD per XML document.
Why use a DTD ?
A DTD can be used to:
–Ensure all required elements are present in the document
–Prevent undefined elements from being used
–Enforce a specific data structure
–Specify the use of attributes and define their possible values
–Define default values for attributes
DECLARINGADTD
An internal DTD is declarations placed in the same file as the document
content. The DOCTYPE declaration for an internal subset is:
<!DOCTYPE root
[
declarations
]>
Where root is the name of the document’s root element, declarations are the
statements that comprise the DTD.
DECLARING A DTD
Example for internal DTD:
<!DOCTYPE customers
[
declarations
]>
DECLARINGADTD
An external DTD is located in a separate file. The DOCTYPE declaration for
an external subset is:
<!DOCTYPE root SYSTEM “uri”>
Where root is the name of the document’s root element, and uri is the filename
of the external subset.
Example:
<!DOCTYPE customers SYSTEM "rules.dtd">
DECLARINGADTD
If you place the DTD within the document, it is easier to compare the DTD to
the document’s content. However, the real power of XML comes from an
external DTD that can be shared among many documents written by
different authors.
DECLARINGADTD
If a document contains both an internal and an external subset, the internal
subset takes precedence over the external subset if there is a conflict
between the two.
This way, the external subset would define basic rules for all the documents,
and the internal subset would define those rules specific to each document.
COMBININGAN EXTERNALAND INTERNAL
DTD SUBSET
Internal DTD
* notice the CDATA section used to insert the address
DECLARING ELEMENTS
DECLARING DOCUMENT ELEMENTS
Every element used in the document must be declared in the DTD for the
document to be valid.
An element type declaration specifies the name of the element and indicates
what kind of content the element can contain.
DECLARING DOCUMENT ELEMENTS
The element declaration syntax is:
<!ELEMENT element content-model>
Where element is the element name and content-model specifies what type of
content the element contains.
* The element name is case sensitive.
TYPES OF CONTENT
DTDs define five different types of content:
1– “ANY” elements. No restrictions on the element’s content.
2– “EMPTY” elements. The element cannot store any content.
3– #PCDATA. The element can only contain text.
4– Elements. The element can only contain child elements.
1- “ANY” content
ANY content: The declared element can store any type of content. The syntax is:
<!ELEMENT element ANY>
ex: if I declare “student” as: <!ELEMENT student ANY>
then I can write in my xml file:
<students>
<student> Maha <student> here the student’s content is #PCDATA
<student>
<name> Sara </name>
</student> here the student’s content is a child element
</students>
2– “EMPTY” content
EMPTY content: This is reserved for elements that store no content. The syntax is:
<!ELEMENT element EMPTY>
ex: if I declare “note” as empty: <!ELEMENT note EMPTY>
then I write the following in my xml file:
<note/>
• Attempting to add content to an empty element would result in XML parsers
rejecting the document as invalid.
3– #PCDATAcontent
Parsed Character Data content: These elements can only contain text strings. The
syntax is:
<!ELEMENT element (#PCDATA)>
• The keyword #PCDATA stands for “parsed-character data” and is any well-formed
text string.
3– #PCDATAcontent
• Example :
if I declare “student” as
<!ELEMENT student (#PCDATA)>
then my xml file would contain:
<student> Lama Alharthi </student>
3– #PCDATAcontent
4- Child Contents
• Element content: The syntax for declaring that elements contain only child
elements is:
<!ELEMENT element (child)> here the element has only one child
• The syntax for a sequence of child elements is:
<!ELEMENT element (child1, child2, …)> here the
element has a sequence of children
Where child is a child element.
• The order of the child elements must match the order defined in the element
declaration.
4- Childcontents
• The declaration
<!ELEMENT customer (phone)>
indicated that the customer element can only have one child, named
phone. You cannot repeat the same child element more than once within
the declaration.
• For example:
<customer>
<phone> 12345 </phone>
</customer>
4- Childcontents
• For example:
<!ELEMENT customer (name, phone, email)>
indicated that the customer element should contain three child elements for
each customer.
<customer>
<name> Ahmed </name>
<phone> 567890 </phone>
<email> Ahmed@hotmail.com </email>
</customer>
4- Childcontents: Choice
Choice is the other way to list child elements and present a set of possible child
elements. The syntax is:
<!ELEMENT element (child1 | child2 | …)>
where child1, child2, etc. are the possible child elements of the parent element.
4- Childcontents: Choice
For example,
<!ELEMENT customer (name | company)>
This allows the customer element to contain either the name element or the company element.
However, you cannot have both the company and the name child elements.
<customers> <customers>
<customer> <customer>
<name> Ahmed </name> OR <company>SQ</company>
</customer> </customer>
</customers> </customers>
4- Childcontents: Sequence & Choice
<!ELEMENT customer ( (name | company) , phone , email )>
Here we have two options:
<customer>
<name> Ahmed </name> OR
<phone> 6666 </phone>
<email> Ahmed@hotmail</email>
<customer>
Notice: we cannot write elements name and company together, we only have to
choose one of them.
<customer>
<company> sabec </company>
<phone> 4444</phone>
<email> info@sabec </email>
<customer>
What if we need more than one occurrence of the same element?
<!ELEMENT customers (customer, customer)>
<!ELEMENT customers (customer, customer, customer)>
<!ELEMENT customers (customer, customer, customer, customer)>
the answer is using modifying symbols to indicate the number of occurrences of a
child element...
MODIFYING SYMBOLS
Modifying symbols are symbols appended to the content model to indicate the number
of occurrences of each element. There are three modifying symbols:
–a question mark (?), allow zero or one of the item.
–a plus sign (+), allow one or more of the item ( at least one).
–an asterisk (*), allow zero or more of the item.
MODIFYING SYMBOLS
For example, <!ELEMENT customers (customer+)> would allow the document to
contain one or more customer elements to be placed within the customer element.
Modifying symbols can be applied within sequences or choices.
<!ELEMENT customer ( name, address, phone, email? )>
MODIFYING SYMBOLS
They can also modify entire element sequences or choices by placing the character
outside the closing parenthesis of the sequence or choice.
<!ELEMENT order (orderDate, items)+>
<order>
<orderDate> 12/12/09 </orderDate>
<items> bread, juice, milk </items>
</order>
<order>
<orderDate> 12/12/09 </orderDate>
<items> bread, juice, milk </items>
<orderDate> 25/12/09 </orderDate>
<items> eggs, milk, bread </items>
</order>
MODIFYING SYMBOLS
They can also modify entire element sequences or choices by placing the character
outside the closing parenthesis of the choice.
<!ELEMENT customer (name | company)+>
+ means: at least one element from the choice list must appear at least once
<customer>
<name> Ahmed </name>
</customer>
<customer>
<company> Sabec </company>
</customer>
<customer>
<name> Ahmed </name>
<company> Sabec </company>
</customer>
<customer>
<name> Ahmed </name>
<name> Sara </name>
</customer>
THE STRUCTURE OF KRISTEN’S DOCUMENT
<!DOCTYPE customers
[ <!ELEMENT customers (customer+)>
<!ELEMENT customer ( name, address, phone,
email?, orders)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
<!ELEMENT email (#PCDATA)>
<!ELEMENT orders (order+)>
<!ELEMENT order ( orderDate, items)>
<!ELEMENT orderDate (#PCDATA)>
<!ELEMENT items (item+)>
<!ELEMENT item (#PCDATA)>
]>
<customers>
<customer>
<name>Ahmed</name>
<address>14 Bronson st.</address>
<phone>12345</phone>
<orders>
<order>
<orderDate>12/12/09</orderDate>
<items>
<item>>bread </item>
</items>
</order>
<order>
<orderDate> 22/01/10</orderDate>
<items>
<item> eggs </item>
<item> milk </item>
</items>
</order>
</orders>
</customer>
<customer>
…………….
</customer>
</customers>
DECLARING
ATTRIBUTES
DECLARINGATTRIBUTES
• For a document to be valid, all the attributes associated with elements must
also be declared. To enforce attribution properties, you must add an
attribute-list declaration to the document’s DTD.
• The attribute-list declaration :
• –Lists the names of all attributes associated with a specific element
• –Specifies the datatype of the attribute
• –Indicates whether the attribute is required or optional
DECLARINGATTRIBUTES
The syntax to declare a list of attributes is:
<!ATTLIST element attribute1 type1 default1
attribute2 type2 default2
attribute3 type3 default3>
Where element is the name of the element associated with the attributes,
attribute is the name of an attribute, type is the attribute’s data type, and
default indicates whether the attribute is required or implied,and whether it
has a fixed or default value.
DECLARINGATTRIBUTES
Another syntax:
<!ATTLIST element attribute1 type1 default1>
<!ATTLIST element attribute2 type2 default2>
<!ATTLIST element attribute3 type3 default3>
Where element is the name of the element associated with the attributes,
attribute is the name of an attribute, type is the attribute’s data type, and
default indicates whether the attribute is required or implied,and whether it
has a fixed or default value.
DECLARINGATTRIBUTES
• Attribute-list declaration can be placed anywhere within the document type
declaration(DTD), although it is easier if they are located adjacent to the
declaration for the element with which they are associated.
ATTRIBUTETYPES
While all attribute types are text strings, you can control the type of text used
with the attribute. There are three general categories of attribute values:
1. CDATA
2. Enumerated
3. ID
WORKING WITHATTRIBUTETYPES:
1- CDATA
• CDATA attributes can contain any character data (text, numbers, symbols)
except reserved XML characters ( <, >, &).
• The general form of a CDATA type is:
<!ATTLIST element attribute CDATA default >
• For example:
<!ATTLIST item itemPrice CDATA ...>
• Any of the following attribute values are allowed under this declaration:
<item itemPrice="29.95"> ... </item>
<item itemPrice="$29.95"> ... </item>
<item itemPrice="£29.95"> ... </item>
WORKING WITHATTRIBUTETYPES:
2- EnumeratedTypes
• Enumerated types are attributes that are limited to a set of possible values.
• The general form of an enumerated type is:
<!ATTLIST element attribute (value1  value2  value3 …) default >
• For example, the following declaration:
<!ATTLIST customer custType (home  business ) ...>
restricts custType to either “home” or “business”
WORKING WITHATTRIBUTETYPES
3- ID
• The ID is used with attributes that require unique values. For example, if a
customer ID needs to be unique, you may use the ID token:
<!ATTLIST customer custID ID …>
• This ensures each customer will have a unique ID.
<customer custID = “123”> …. </customer>
• However, the following elements would not be valid because the same
custID value is used more than once:
<customer custID="Cust021"> ... </customer>
<customer custID="Cust021"> ... </customer>
ATTRIBUTE DEFAULTS
The final part of an attribute declaration is the attribute default. There are two possible
defaults:
– #REQUIRED: the attribute must appear with every occurrence of the element.
– #IMPLIED: The attribute is optional.
• The #REQUIRED value to the attribute declaration:
<!ATTLIST customer custID ID #REQUIRED>
• The #IMPLIED value for the custType attribute to indicate that use of this attribute is
optional:
<!ATTLIST customer custType (home | business) #IMPLIED>
Ad

More Related Content

What's hot (20)

Transforming xml with XSLT
Transforming  xml with XSLTTransforming  xml with XSLT
Transforming xml with XSLT
Malintha Adikari
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
Amin Choroomi
 
Xsd examples
Xsd examplesXsd examples
Xsd examples
Bình Trọng Án
 
Xml schema
Xml schemaXml schema
Xml schema
Harry Potter
 
Unit iv xml
Unit iv xmlUnit iv xml
Unit iv xml
smitha273566
 
XML Schema
XML SchemaXML Schema
XML Schema
Kumar
 
XSLT
XSLTXSLT
XSLT
Surinder Kaur
 
Xml schema
Xml schemaXml schema
Xml schema
Prabhakaran V M
 
XML/XSLT
XML/XSLTXML/XSLT
XML/XSLT
thinkahead.net
 
XML Schemas
XML SchemasXML Schemas
XML Schemas
People Strategists
 
XML SCHEMAS
XML SCHEMASXML SCHEMAS
XML SCHEMAS
SaraswathiRamalingam
 
XSLT
XSLTXSLT
XSLT
rpoplai
 
Xml Schema
Xml SchemaXml Schema
Xml Schema
vikram singh
 
Xslt
XsltXslt
Xslt
Mahara Jothi
 
Xslt tutorial
Xslt tutorialXslt tutorial
Xslt tutorial
Bijoy Kureekkal
 
Learning XSLT
Learning XSLTLearning XSLT
Learning XSLT
Overdue Books LLC
 
XSLT presentation
XSLT presentationXSLT presentation
XSLT presentation
Miguel Angel Teheran Garcia
 
Regular expression unit2
Regular expression unit2Regular expression unit2
Regular expression unit2
smitha273566
 
XSLT. Basic.
XSLT. Basic.XSLT. Basic.
XSLT. Basic.
Alexander Kirillov
 
Introduction to SQL (for Chicago Booth MBA technology club)
Introduction to SQL (for Chicago Booth MBA technology club)Introduction to SQL (for Chicago Booth MBA technology club)
Introduction to SQL (for Chicago Booth MBA technology club)
Jennifer Berk
 

Similar to Xml part2 (20)

II UNIT PPT NOTES.pdf this is the data structures
II UNIT PPT NOTES.pdf this is the data structuresII UNIT PPT NOTES.pdf this is the data structures
II UNIT PPT NOTES.pdf this is the data structures
PriyankaRamavath3
 
Dtd
DtdDtd
Dtd
Abhishek Kesharwani
 
distributed system concerned lab sessions
distributed system concerned lab sessionsdistributed system concerned lab sessions
distributed system concerned lab sessions
milkesa13
 
2-DTD.ppt
2-DTD.ppt2-DTD.ppt
2-DTD.ppt
KGSCSEPSGCT
 
Web Security Extensible Markup Language.pptx
Web Security Extensible Markup Language.pptxWeb Security Extensible Markup Language.pptx
Web Security Extensible Markup Language.pptx
SidduSKamatar
 
it8074-soa-uniti-.pdf
it8074-soa-uniti-.pdfit8074-soa-uniti-.pdf
it8074-soa-uniti-.pdf
FreeFire293813
 
It8074 soa-unit i
It8074 soa-unit iIt8074 soa-unit i
It8074 soa-unit i
RevathiAPICSE
 
Unit-III_JQuery.pptx engineering subject for third year students
Unit-III_JQuery.pptx engineering subject for third year studentsUnit-III_JQuery.pptx engineering subject for third year students
Unit-III_JQuery.pptx engineering subject for third year students
MARasheed3
 
web design technology- mark up languages
web design technology- mark up languagesweb design technology- mark up languages
web design technology- mark up languages
ssuser2efca7
 
Unit 5 xml (1)
Unit 5   xml (1)Unit 5   xml (1)
Unit 5 xml (1)
manochitra10
 
It8074 soa-unit i
It8074 soa-unit iIt8074 soa-unit i
It8074 soa-unit i
smitha273566
 
Xml2
Xml2Xml2
Xml2
Abhishek Kesharwani
 
Xml
XmlXml
Xml
sudhakar mandal
 
Xml11
Xml11Xml11
Xml11
Sudharsan S
 
Xml Presentation-1
Xml Presentation-1Xml Presentation-1
Xml Presentation-1
Sudharsan S
 
uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2uptu web technology unit 2 Xml2
uptu web technology unit 2 Xml2
Abhishek Kesharwani
 
XML.ppt
XML.pptXML.ppt
XML.ppt
edwinmacaspag1
 
Web Technologies Unit 2 Print.pdf
Web Technologies Unit 2 Print.pdfWeb Technologies Unit 2 Print.pdf
Web Technologies Unit 2 Print.pdf
AnonymousXhmybK
 
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
M.FLORENCE DAYANA WEB DESIGN -Unit 5   XMLM.FLORENCE DAYANA WEB DESIGN -Unit 5   XML
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
Dr.Florence Dayana
 
01 xml document structure
01 xml document structure01 xml document structure
01 xml document structure
Baskarkncet
 
II UNIT PPT NOTES.pdf this is the data structures
II UNIT PPT NOTES.pdf this is the data structuresII UNIT PPT NOTES.pdf this is the data structures
II UNIT PPT NOTES.pdf this is the data structures
PriyankaRamavath3
 
distributed system concerned lab sessions
distributed system concerned lab sessionsdistributed system concerned lab sessions
distributed system concerned lab sessions
milkesa13
 
Web Security Extensible Markup Language.pptx
Web Security Extensible Markup Language.pptxWeb Security Extensible Markup Language.pptx
Web Security Extensible Markup Language.pptx
SidduSKamatar
 
Unit-III_JQuery.pptx engineering subject for third year students
Unit-III_JQuery.pptx engineering subject for third year studentsUnit-III_JQuery.pptx engineering subject for third year students
Unit-III_JQuery.pptx engineering subject for third year students
MARasheed3
 
web design technology- mark up languages
web design technology- mark up languagesweb design technology- mark up languages
web design technology- mark up languages
ssuser2efca7
 
Xml Presentation-1
Xml Presentation-1Xml Presentation-1
Xml Presentation-1
Sudharsan S
 
Web Technologies Unit 2 Print.pdf
Web Technologies Unit 2 Print.pdfWeb Technologies Unit 2 Print.pdf
Web Technologies Unit 2 Print.pdf
AnonymousXhmybK
 
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
M.FLORENCE DAYANA WEB DESIGN -Unit 5   XMLM.FLORENCE DAYANA WEB DESIGN -Unit 5   XML
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
Dr.Florence Dayana
 
01 xml document structure
01 xml document structure01 xml document structure
01 xml document structure
Baskarkncet
 
Ad

Recently uploaded (20)

Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Vasileios Komianos
 
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
Toru Tamaki
 
machines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdfmachines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdf
AmirStern2
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
Unlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web AppsUnlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web Apps
Maximiliano Firtman
 
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Gary Arora
 
MEMS IC Substrate Technologies Guide 2025.pptx
MEMS IC Substrate Technologies Guide 2025.pptxMEMS IC Substrate Technologies Guide 2025.pptx
MEMS IC Substrate Technologies Guide 2025.pptx
IC substrate Shawn Wang
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
Artificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptxArtificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptx
03ANMOLCHAURASIYA
 
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdfICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
Eryk Budi Pratama
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Christian Folini
 
Top-AI-Based-Tools-for-Game-Developers (1).pptx
Top-AI-Based-Tools-for-Game-Developers (1).pptxTop-AI-Based-Tools-for-Game-Developers (1).pptx
Top-AI-Based-Tools-for-Game-Developers (1).pptx
BR Softech
 
Why Slack Should Be Your Next Business Tool? (Tips to Make Most out of Slack)
Why Slack Should Be Your Next Business Tool? (Tips to Make Most out of Slack)Why Slack Should Be Your Next Business Tool? (Tips to Make Most out of Slack)
Why Slack Should Be Your Next Business Tool? (Tips to Make Most out of Slack)
Cyntexa
 
Agentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community MeetupAgentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community Meetup
Manoj Batra (1600 + Connections)
 
Understanding SEO in the Age of AI.pdf
Understanding SEO in the Age of AI.pdfUnderstanding SEO in the Age of AI.pdf
Understanding SEO in the Age of AI.pdf
Fulcrum Concepts, LLC
 
Build With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdfBuild With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdf
Google Developer Group - Harare
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Vasileios Komianos
 
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
Toru Tamaki
 
machines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdfmachines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdf
AmirStern2
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
Unlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web AppsUnlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web Apps
Maximiliano Firtman
 
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Gary Arora
 
MEMS IC Substrate Technologies Guide 2025.pptx
MEMS IC Substrate Technologies Guide 2025.pptxMEMS IC Substrate Technologies Guide 2025.pptx
MEMS IC Substrate Technologies Guide 2025.pptx
IC substrate Shawn Wang
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
Artificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptxArtificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptx
03ANMOLCHAURASIYA
 
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdfICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
ICDCC 2025: Securing Agentic AI - Eryk Budi Pratama.pdf
Eryk Budi Pratama
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Christian Folini
 
Top-AI-Based-Tools-for-Game-Developers (1).pptx
Top-AI-Based-Tools-for-Game-Developers (1).pptxTop-AI-Based-Tools-for-Game-Developers (1).pptx
Top-AI-Based-Tools-for-Game-Developers (1).pptx
BR Softech
 
Why Slack Should Be Your Next Business Tool? (Tips to Make Most out of Slack)
Why Slack Should Be Your Next Business Tool? (Tips to Make Most out of Slack)Why Slack Should Be Your Next Business Tool? (Tips to Make Most out of Slack)
Why Slack Should Be Your Next Business Tool? (Tips to Make Most out of Slack)
Cyntexa
 
Understanding SEO in the Age of AI.pdf
Understanding SEO in the Age of AI.pdfUnderstanding SEO in the Age of AI.pdf
Understanding SEO in the Age of AI.pdf
Fulcrum Concepts, LLC
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Ad

Xml part2

  • 2. Agenda • Validating a Document • DTD • Declaring Elements • Declaring Attributes
  • 3. VALIDATINGADOCUMENT You validate documents to make certain necessary elements are never omitted. For example, each customer order should include a customer name, address, and phone number. • Some elements and attributes may be optional, for example an e-mail address. • An XML document can be validated using either DTDs (Document Type Definitions) or schemas.
  • 4. WELL-FORMEDVS.VALID XMLDOCUMENTS • An XML document is well-formed if it contains no syntax errors and fulfills all of the specifications for XML code as defined by the W3C. • An XML document is valid if it is well-formed and also satisfies the rules laid out in the DTD or schema attached to the document.
  • 5. DocumentTypeDefinitions (DTD) • A DTD is a collection of rules or declarations that define the content and structure of the document. • A DTD attaches those rules to the document’s content. • There can only be one DTD per XML document.
  • 6. Why use a DTD ? A DTD can be used to: –Ensure all required elements are present in the document –Prevent undefined elements from being used –Enforce a specific data structure –Specify the use of attributes and define their possible values –Define default values for attributes
  • 7. DECLARINGADTD An internal DTD is declarations placed in the same file as the document content. The DOCTYPE declaration for an internal subset is: <!DOCTYPE root [ declarations ]> Where root is the name of the document’s root element, declarations are the statements that comprise the DTD.
  • 8. DECLARING A DTD Example for internal DTD: <!DOCTYPE customers [ declarations ]>
  • 9. DECLARINGADTD An external DTD is located in a separate file. The DOCTYPE declaration for an external subset is: <!DOCTYPE root SYSTEM “uri”> Where root is the name of the document’s root element, and uri is the filename of the external subset. Example: <!DOCTYPE customers SYSTEM "rules.dtd">
  • 10. DECLARINGADTD If you place the DTD within the document, it is easier to compare the DTD to the document’s content. However, the real power of XML comes from an external DTD that can be shared among many documents written by different authors.
  • 11. DECLARINGADTD If a document contains both an internal and an external subset, the internal subset takes precedence over the external subset if there is a conflict between the two. This way, the external subset would define basic rules for all the documents, and the internal subset would define those rules specific to each document.
  • 13. Internal DTD * notice the CDATA section used to insert the address
  • 15. DECLARING DOCUMENT ELEMENTS Every element used in the document must be declared in the DTD for the document to be valid. An element type declaration specifies the name of the element and indicates what kind of content the element can contain.
  • 16. DECLARING DOCUMENT ELEMENTS The element declaration syntax is: <!ELEMENT element content-model> Where element is the element name and content-model specifies what type of content the element contains. * The element name is case sensitive.
  • 17. TYPES OF CONTENT DTDs define five different types of content: 1– “ANY” elements. No restrictions on the element’s content. 2– “EMPTY” elements. The element cannot store any content. 3– #PCDATA. The element can only contain text. 4– Elements. The element can only contain child elements.
  • 18. 1- “ANY” content ANY content: The declared element can store any type of content. The syntax is: <!ELEMENT element ANY> ex: if I declare “student” as: <!ELEMENT student ANY> then I can write in my xml file: <students> <student> Maha <student> here the student’s content is #PCDATA <student> <name> Sara </name> </student> here the student’s content is a child element </students>
  • 19. 2– “EMPTY” content EMPTY content: This is reserved for elements that store no content. The syntax is: <!ELEMENT element EMPTY> ex: if I declare “note” as empty: <!ELEMENT note EMPTY> then I write the following in my xml file: <note/> • Attempting to add content to an empty element would result in XML parsers rejecting the document as invalid.
  • 20. 3– #PCDATAcontent Parsed Character Data content: These elements can only contain text strings. The syntax is: <!ELEMENT element (#PCDATA)> • The keyword #PCDATA stands for “parsed-character data” and is any well-formed text string.
  • 21. 3– #PCDATAcontent • Example : if I declare “student” as <!ELEMENT student (#PCDATA)> then my xml file would contain: <student> Lama Alharthi </student>
  • 23. 4- Child Contents • Element content: The syntax for declaring that elements contain only child elements is: <!ELEMENT element (child)> here the element has only one child • The syntax for a sequence of child elements is: <!ELEMENT element (child1, child2, …)> here the element has a sequence of children Where child is a child element. • The order of the child elements must match the order defined in the element declaration.
  • 24. 4- Childcontents • The declaration <!ELEMENT customer (phone)> indicated that the customer element can only have one child, named phone. You cannot repeat the same child element more than once within the declaration. • For example: <customer> <phone> 12345 </phone> </customer>
  • 25. 4- Childcontents • For example: <!ELEMENT customer (name, phone, email)> indicated that the customer element should contain three child elements for each customer. <customer> <name> Ahmed </name> <phone> 567890 </phone> <email> Ahmed@hotmail.com </email> </customer>
  • 26. 4- Childcontents: Choice Choice is the other way to list child elements and present a set of possible child elements. The syntax is: <!ELEMENT element (child1 | child2 | …)> where child1, child2, etc. are the possible child elements of the parent element.
  • 27. 4- Childcontents: Choice For example, <!ELEMENT customer (name | company)> This allows the customer element to contain either the name element or the company element. However, you cannot have both the company and the name child elements. <customers> <customers> <customer> <customer> <name> Ahmed </name> OR <company>SQ</company> </customer> </customer> </customers> </customers>
  • 28. 4- Childcontents: Sequence & Choice <!ELEMENT customer ( (name | company) , phone , email )> Here we have two options: <customer> <name> Ahmed </name> OR <phone> 6666 </phone> <email> Ahmed@hotmail</email> <customer> Notice: we cannot write elements name and company together, we only have to choose one of them. <customer> <company> sabec </company> <phone> 4444</phone> <email> info@sabec </email> <customer>
  • 29. What if we need more than one occurrence of the same element? <!ELEMENT customers (customer, customer)> <!ELEMENT customers (customer, customer, customer)> <!ELEMENT customers (customer, customer, customer, customer)> the answer is using modifying symbols to indicate the number of occurrences of a child element...
  • 30. MODIFYING SYMBOLS Modifying symbols are symbols appended to the content model to indicate the number of occurrences of each element. There are three modifying symbols: –a question mark (?), allow zero or one of the item. –a plus sign (+), allow one or more of the item ( at least one). –an asterisk (*), allow zero or more of the item.
  • 31. MODIFYING SYMBOLS For example, <!ELEMENT customers (customer+)> would allow the document to contain one or more customer elements to be placed within the customer element. Modifying symbols can be applied within sequences or choices. <!ELEMENT customer ( name, address, phone, email? )>
  • 32. MODIFYING SYMBOLS They can also modify entire element sequences or choices by placing the character outside the closing parenthesis of the sequence or choice. <!ELEMENT order (orderDate, items)+> <order> <orderDate> 12/12/09 </orderDate> <items> bread, juice, milk </items> </order> <order> <orderDate> 12/12/09 </orderDate> <items> bread, juice, milk </items> <orderDate> 25/12/09 </orderDate> <items> eggs, milk, bread </items> </order>
  • 33. MODIFYING SYMBOLS They can also modify entire element sequences or choices by placing the character outside the closing parenthesis of the choice. <!ELEMENT customer (name | company)+> + means: at least one element from the choice list must appear at least once <customer> <name> Ahmed </name> </customer> <customer> <company> Sabec </company> </customer> <customer> <name> Ahmed </name> <company> Sabec </company> </customer> <customer> <name> Ahmed </name> <name> Sara </name> </customer>
  • 34. THE STRUCTURE OF KRISTEN’S DOCUMENT
  • 35. <!DOCTYPE customers [ <!ELEMENT customers (customer+)> <!ELEMENT customer ( name, address, phone, email?, orders)> <!ELEMENT name (#PCDATA)> <!ELEMENT address (#PCDATA)> <!ELEMENT phone (#PCDATA)> <!ELEMENT email (#PCDATA)> <!ELEMENT orders (order+)> <!ELEMENT order ( orderDate, items)> <!ELEMENT orderDate (#PCDATA)> <!ELEMENT items (item+)> <!ELEMENT item (#PCDATA)> ]> <customers> <customer> <name>Ahmed</name> <address>14 Bronson st.</address> <phone>12345</phone> <orders> <order> <orderDate>12/12/09</orderDate> <items> <item>>bread </item> </items> </order> <order> <orderDate> 22/01/10</orderDate> <items> <item> eggs </item> <item> milk </item> </items> </order> </orders> </customer> <customer> ……………. </customer> </customers>
  • 37. DECLARINGATTRIBUTES • For a document to be valid, all the attributes associated with elements must also be declared. To enforce attribution properties, you must add an attribute-list declaration to the document’s DTD. • The attribute-list declaration : • –Lists the names of all attributes associated with a specific element • –Specifies the datatype of the attribute • –Indicates whether the attribute is required or optional
  • 38. DECLARINGATTRIBUTES The syntax to declare a list of attributes is: <!ATTLIST element attribute1 type1 default1 attribute2 type2 default2 attribute3 type3 default3> Where element is the name of the element associated with the attributes, attribute is the name of an attribute, type is the attribute’s data type, and default indicates whether the attribute is required or implied,and whether it has a fixed or default value.
  • 39. DECLARINGATTRIBUTES Another syntax: <!ATTLIST element attribute1 type1 default1> <!ATTLIST element attribute2 type2 default2> <!ATTLIST element attribute3 type3 default3> Where element is the name of the element associated with the attributes, attribute is the name of an attribute, type is the attribute’s data type, and default indicates whether the attribute is required or implied,and whether it has a fixed or default value.
  • 40. DECLARINGATTRIBUTES • Attribute-list declaration can be placed anywhere within the document type declaration(DTD), although it is easier if they are located adjacent to the declaration for the element with which they are associated.
  • 41. ATTRIBUTETYPES While all attribute types are text strings, you can control the type of text used with the attribute. There are three general categories of attribute values: 1. CDATA 2. Enumerated 3. ID
  • 42. WORKING WITHATTRIBUTETYPES: 1- CDATA • CDATA attributes can contain any character data (text, numbers, symbols) except reserved XML characters ( <, >, &). • The general form of a CDATA type is: <!ATTLIST element attribute CDATA default > • For example: <!ATTLIST item itemPrice CDATA ...> • Any of the following attribute values are allowed under this declaration: <item itemPrice="29.95"> ... </item> <item itemPrice="$29.95"> ... </item> <item itemPrice="£29.95"> ... </item>
  • 43. WORKING WITHATTRIBUTETYPES: 2- EnumeratedTypes • Enumerated types are attributes that are limited to a set of possible values. • The general form of an enumerated type is: <!ATTLIST element attribute (value1 value2 value3 …) default > • For example, the following declaration: <!ATTLIST customer custType (home business ) ...> restricts custType to either “home” or “business”
  • 44. WORKING WITHATTRIBUTETYPES 3- ID • The ID is used with attributes that require unique values. For example, if a customer ID needs to be unique, you may use the ID token: <!ATTLIST customer custID ID …> • This ensures each customer will have a unique ID. <customer custID = “123”> …. </customer> • However, the following elements would not be valid because the same custID value is used more than once: <customer custID="Cust021"> ... </customer> <customer custID="Cust021"> ... </customer>
  • 45. ATTRIBUTE DEFAULTS The final part of an attribute declaration is the attribute default. There are two possible defaults: – #REQUIRED: the attribute must appear with every occurrence of the element. – #IMPLIED: The attribute is optional. • The #REQUIRED value to the attribute declaration: <!ATTLIST customer custID ID #REQUIRED> • The #IMPLIED value for the custType attribute to indicate that use of this attribute is optional: <!ATTLIST customer custType (home | business) #IMPLIED>
  翻译: