SlideShare una empresa de Scribd logo
1 de 71
Introduction
Nguyễn Đăng Khoa
Content
• What is XML?
• Well-Formed XML
• XML Namespaces
What is XML?
• Stands for Extensible Markup Language
• First draft was published in 1996
• A revised version as recommendation on Feb
10, 1998 (by W3C)
• XML derived as a subset of SGML (Standard
Generalized Markup Language)
XML’s goals
• Before XML
– Data formats were proprietary
• Goals:
– To make data more interchangeable
– Is readable by both humans and machines
Data-centric vs. Document-centric
• 2 main types of XML formats
– Store pure data: configuration
– Add metadata to documents: XHTML
Advantages
• A clear separation between data and
presentation
• Easy extensibility of XML files
• Hierarchical Data Representation
• Interoperability
Disadvantages
• Increase in the size of the file
XML In Practice
• Configuration Files
• Web Services
• Web Content (XHTML)
• Document Management
• Database Systems
• Image Representation
• Business Interoperability
Well-Formed XML
Well-Formed XML - XML Prolog
Well-Formed XML - XML Prolog
• Optional
• Must come first
• version
• 1.0 (default) or 1.1
• encoding
• UTF-8 (default) or
variety of Unicode
• standalone
• yes (default) or no
Well-Formed XML - Comment
Well-Formed XML - Comment
• Human read
<!-- comment -->
Well-Formed XML – Root element
Well-Formed XML – Root element
• Must have one and only
one in document
• Everything else lies
under this element to
form a hierarchical tree
Well-Formed XML – Elements
Well-Formed XML – Elements
• Basic building blocks
• Can be used to show
individual or repetitive
items of data
• 2 ways to define
<element>
content
</element>
<element />
Well-Formed XML – Elements
• All elements must be
nested underneath the
root element
• You can’t have the end tag
of an element before the
end tag of one nested
below it
<myElement>
<elementA>
<elementB>
</elementA>
</elementB>
</myElement>
Well-Formed XML – Naming Styles
• Pascal-casing
<MyElement />
• Camel-casing
<myElement />
• Underscored names
<my_element />
• Hyphenated names
<my-element />
Well-Formed XML – Naming
Specifications
• can begin with either an
underscore or an
uppercase or lowercase
letter from the Unicode
character set
• Subsequent characters can
also be a dash (-) or a digit
• Case-sensitive
• the start and end tags
must match exactly
• cannot contain spaces
Well-Formed XML – Naming
Specifications - Examples
Well-Formed XML – Naming
Specifications - Examples
Well-Formed XML – Exercise
• <list><title>The first list</title><item>An item</list>
• <item>An item</item><item>Another item</item>
• <para>Bathing a cat is a <emph>relatively</emph>
easy task as long as the cat is willing.</para>
• <bibl><title>How to Bathe a Cat<author></title>Merlin
Bauer<author></bibl>
Well-Formed XML - Attributes
Well-Formed XML - Attributes
• name-value pairs
associated with an
element
Well-Formed XML – Attributes - Rules
• consist of a name and a
value separated by an
equals sign
• The name follows the
same rules as element
names
• The value must be in
quotes
• There must be a value part
• Attribute names must be
unique per element
Well-Formed XML – Attributes -
Examples
Well-Formed XML – Attributes -
Examples
Well-Formed XML – Character content
- Restrictions
Well-Formed XML – Character content
- Restrictions
• Ampersand (&)
• Left angle bracket (<)
Well-Formed XML – Entity and
Character References
• There are two ways of inserting characters into a
document that cannot be used directly
– Entity references
• Start with an ampersand (&)
and finish with a semicolon (;)
• There are five built-in
entity references in XML
– Character references
• Begin with &# and end with a semicolon (;)
• Example: the Greek letter omega (Ω) as a reference it would
be &#x03A9; in hexadecimal or &#937; in decimal
Well-Formed XML – Entity and
Character References
Well-Formed XML – Entity and
Character References
<!DOCTYPE myElement [
<!ENTITY copyright “© Wrox 2012”>
]>
Well-Formed XML – Elements Versus
Attributes
Well-Formed XML – Elements Versus
Attributes
Rule ????
Well-Formed XML – Elements Versus
Attributes
Attributes
• There is only one piece of
data
• Names cannot be repeated
• Make file size is smaller
– Good to sent across network
Elements
• The data is not a simple
type
• Items may need to be
repeated
• Items can be ordered
• A large amount of content
that is just text
Well-Formed XML – Elements Versus
Attributes - Examples
Well-Formed XML – Elements Versus
Attributes - Examples
Well-Formed XML – Processing
Instructions
• is used to communicate with the application
that is consuming the XML
– It is not used directly by the XML parser at all
Well-Formed XML – CDATA
• These are used as a way to avoid repetitive
escaping of characters
• Starts with <![CDATA[ and ends with ]]>
• Example: you want data in your document
1 kilometer < 1 mile
1 pint < 1 liter
1 pound < 1 kilogram
Well-Formed XML – CDATA
Well-Formed XML – CDATA
• A common use of CDATA is in XHTML, the XML
version of HTML
Well-Formed XML – CDATA
• A common use of CDATA is in XHTML, the XML
version of HTML
Well-Formed XML – Exercise
XML Namespaces – Example
You need a
new table
Dining
table
Database
table
HTML
table
XML Namespaces
• A way of grouping elements and attributes
under a common heading in order to
differentiate them from similarly-named items
XML Namespaces – Example
XML Namespaces – Example
XML Namespaces – Why do you need
namespaces?
• You won’t always be using own XML formats
entirely within your own systems
XML Namespaces – How do you
choose a namespace?
• In Java, are called packages
• In C#, are called namespaces
– System.Windows.Forms.Timer
– System.Timers.Timer
– System.Threading.Timer
XML Namespaces – How do you
choose a namespace?
• You can choose virtually any string of
characters to make sure your element’s full
name is unique
• W3C recommend
– URIs
URLs, URIs, and URNs
• URL is a Uniform Resource Locator, tells you the
how and where of something
– [Scheme]://[Domain]:[Port]/[Path]?[QueryString]#[Fra
gmentId]
– http://www.wrox.com/remtitle.cgi?isgn=0470114878
• URN is a Uniform Resource Name, is simply a
unique name
– urn:[namespace identifier]:[namespace specific string]
– urn:isbn:9780470114872
• URI is a Uniform Resource Identifier, is URL or
URN
XML Namespaces – How to declare a
namespace?
• If you want all elements to be under the
namespace
– Declare a default namespace
XML Namespaces – How to declare a
namespace?
• If you want specific elements to be under the
namespace
– Declare a namespace explicitly
– Choose prefix to represent namespace
• Some prefixes are reserved, such as xml, xmlns, and any
other combinations beginning with the characters xml
XML Namespaces – How to declare a
namespace?
Qualified
Name
(QName)
Local Name
XML Namespaces – How to declare a
namespace?
XML Namespaces – Declaring more
than one namespace
• <applicationUsers> element belongs to
http://wrox.com/namespaces/applications/hr
/config namespace
• <user> elements belong to
http://wrox.com/namespaces/general/entities
namespace
XML Namespaces – Declaring more
than one namespace
XML Namespaces – Declaring more
than one namespace
XML Namespaces
XML Namespaces – Real world
• XML Schemas
– Defining the structure of a document
• Combination documents
– Merging documents from more than one source
• Versioning
– Differentiating between different versions of an
XML format
XML Namespaces – Combination
documents
XML Namespaces – Versioning
• Differentiating between different versions of an XML
format
• Go back to employees.xml
– Namespace is
http://wrox.com/namespaces/general/employee
– Newer version:
http://wrox.com/namespaces/general/employee/
v2
XML Namespaces – Versioning
How do I want the application to
handle the two different versions?
XML Namespaces – Versioning
• Version one of the application opens a version
one file
• Version one of the application opens a version
two file
• Version two of the application opens a version
one file
• Version two of the application opens a version
two file
XML Namespaces – Versioning –
Practical
XML Namespaces – When to use and
not use namespaces
When namespaces are needed
• When there’s no choice
• When you need
interoperability
• When you need validation
When namespaces are not
needed
• When you have the need to
store or exchange data for
relatively small documents
that will be seen only by a
limited number of systems
XML Namespaces – Common
namespaces
• The XML Namespace
http://www.w3.org/XML/1998/namespace
– Attributes:
• xml:lang
• xml:space
• xml:base
• xml:id
• xml:Father
XML Namespaces – Common
namespaces
• The XMLNS Namespace
http://www.w3.org/2000/xmlns/
• The XML Schema Namespace
http://www.w3.org/2001/XMLSchema
• The XSLT Namespace (xsl or xslt)
http://www.w3.org/1999/XSL/Transform
• The SOAP Namespace (soap, soap12)
http://schemas.xmlsoap.org/soap/envelope/ (SOAP 1.1)
http://www.w3.org/2003/05/soap-envelope (SOAP 1.2)
• The WSDL Namespace (wsdl)
http://www.w3.org/ns/wsdl (1.0, 2.0)
XML Namespaces – Common
namespaces
• The Atom Namespace
http://www.w3.org/2005/Atom
• The MathML Namespace
http://www.w3.org/1998/Math/MathML
• The Docbook Namespace
http://docbook.org/ns/docbook
XML Namespaces – Exercise

Más contenido relacionado

La actualidad más candente (20)

From Ontology to Wiki: Automating Generation of Semantic Wiki Interfaces from...
From Ontology to Wiki: Automating Generation of Semantic Wiki Interfaces from...From Ontology to Wiki: Automating Generation of Semantic Wiki Interfaces from...
From Ontology to Wiki: Automating Generation of Semantic Wiki Interfaces from...
 
Querring xml with xpath
Querring xml with xpath Querring xml with xpath
Querring xml with xpath
 
Xml basics
Xml basicsXml basics
Xml basics
 
Introduction to SQL Alchemy - SyPy June 2013
Introduction to SQL Alchemy - SyPy June 2013Introduction to SQL Alchemy - SyPy June 2013
Introduction to SQL Alchemy - SyPy June 2013
 
Android de la A a la Z XML Ulises Gonzalez
Android de la A a la Z  XML Ulises GonzalezAndroid de la A a la Z  XML Ulises Gonzalez
Android de la A a la Z XML Ulises Gonzalez
 
XMl
XMlXMl
XMl
 
XML
XMLXML
XML
 
XML
XMLXML
XML
 
DSpace 4.2 Transmission: Import/Export
DSpace 4.2 Transmission: Import/ExportDSpace 4.2 Transmission: Import/Export
DSpace 4.2 Transmission: Import/Export
 
Sax Dom Tutorial
Sax Dom TutorialSax Dom Tutorial
Sax Dom Tutorial
 
Xml processors
Xml processorsXml processors
Xml processors
 
SFDC Introduction to Apex
SFDC Introduction to ApexSFDC Introduction to Apex
SFDC Introduction to Apex
 
Oracle by Muhammad Iqbal
Oracle by Muhammad IqbalOracle by Muhammad Iqbal
Oracle by Muhammad Iqbal
 
3 sql overview
3 sql overview3 sql overview
3 sql overview
 
Stored procedures
Stored proceduresStored procedures
Stored procedures
 
Jdom how it works & how it opened the java process
Jdom how it works & how it opened the java processJdom how it works & how it opened the java process
Jdom how it works & how it opened the java process
 
2015-04-11-PseudoConstants
2015-04-11-PseudoConstants2015-04-11-PseudoConstants
2015-04-11-PseudoConstants
 
Learning XSLT
Learning XSLTLearning XSLT
Learning XSLT
 
Transforming xml with XSLT
Transforming  xml with XSLTTransforming  xml with XSLT
Transforming xml with XSLT
 
Unit iv xml
Unit iv xmlUnit iv xml
Unit iv xml
 

Destacado (17)

Xml intro1
Xml intro1Xml intro1
Xml intro1
 
Xml3
Xml3Xml3
Xml3
 
Semantic web xml-rdf-dom parser
Semantic web xml-rdf-dom parserSemantic web xml-rdf-dom parser
Semantic web xml-rdf-dom parser
 
Session 5
Session 5Session 5
Session 5
 
Dino's DEV Project
Dino's DEV ProjectDino's DEV Project
Dino's DEV Project
 
Data Intechange at Work: XML and JSON
Data Intechange at Work: XML and JSONData Intechange at Work: XML and JSON
Data Intechange at Work: XML and JSON
 
Xml parsers
Xml parsersXml parsers
Xml parsers
 
XML SAX PARSING
XML SAX PARSING XML SAX PARSING
XML SAX PARSING
 
Parsing XML Data
Parsing XML DataParsing XML Data
Parsing XML Data
 
5 xml parsing
5   xml parsing5   xml parsing
5 xml parsing
 
XML DOM
XML DOMXML DOM
XML DOM
 
java API for XML DOM
java API for XML DOMjava API for XML DOM
java API for XML DOM
 
Xsd examples
Xsd examplesXsd examples
Xsd examples
 
6 xml parsing
6   xml parsing6   xml parsing
6 xml parsing
 
XML Document Object Model (DOM)
XML Document Object Model (DOM)XML Document Object Model (DOM)
XML Document Object Model (DOM)
 
Dom parser
Dom parserDom parser
Dom parser
 
DOM and SAX
DOM and SAXDOM and SAX
DOM and SAX
 

Similar a Introduce to XML (20)

XML
XMLXML
XML
 
1 xml fundamentals
1 xml fundamentals1 xml fundamentals
1 xml fundamentals
 
Unit3wt
Unit3wtUnit3wt
Unit3wt
 
Xml unit1
Xml unit1Xml unit1
Xml unit1
 
Xmll
XmllXmll
Xmll
 
Ch2 neworder
Ch2 neworderCh2 neworder
Ch2 neworder
 
Xml iet 2015
Xml iet 2015Xml iet 2015
Xml iet 2015
 
Xml
XmlXml
Xml
 
Unit iv xml dom
Unit iv xml domUnit iv xml dom
Unit iv xml dom
 
XML and XPath details
XML and XPath detailsXML and XPath details
XML and XPath details
 
Xml
XmlXml
Xml
 
Xml passing in java
Xml passing in javaXml passing in java
Xml passing in java
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 
Xml and webdata
Xml and webdataXml and webdata
Xml and webdata
 
Xml
XmlXml
Xml
 

Último

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Último (20)

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 

Introduce to XML

  • 2. Content • What is XML? • Well-Formed XML • XML Namespaces
  • 3. What is XML? • Stands for Extensible Markup Language • First draft was published in 1996 • A revised version as recommendation on Feb 10, 1998 (by W3C) • XML derived as a subset of SGML (Standard Generalized Markup Language)
  • 4. XML’s goals • Before XML – Data formats were proprietary • Goals: – To make data more interchangeable – Is readable by both humans and machines
  • 5. Data-centric vs. Document-centric • 2 main types of XML formats – Store pure data: configuration – Add metadata to documents: XHTML
  • 6. Advantages • A clear separation between data and presentation • Easy extensibility of XML files • Hierarchical Data Representation • Interoperability
  • 7. Disadvantages • Increase in the size of the file
  • 8. XML In Practice • Configuration Files • Web Services • Web Content (XHTML) • Document Management • Database Systems • Image Representation • Business Interoperability
  • 10. Well-Formed XML - XML Prolog
  • 11. Well-Formed XML - XML Prolog • Optional • Must come first • version • 1.0 (default) or 1.1 • encoding • UTF-8 (default) or variety of Unicode • standalone • yes (default) or no
  • 12. Well-Formed XML - Comment
  • 13. Well-Formed XML - Comment • Human read <!-- comment -->
  • 14. Well-Formed XML – Root element
  • 15. Well-Formed XML – Root element • Must have one and only one in document • Everything else lies under this element to form a hierarchical tree
  • 17. Well-Formed XML – Elements • Basic building blocks • Can be used to show individual or repetitive items of data • 2 ways to define <element> content </element> <element />
  • 18. Well-Formed XML – Elements • All elements must be nested underneath the root element • You can’t have the end tag of an element before the end tag of one nested below it <myElement> <elementA> <elementB> </elementA> </elementB> </myElement>
  • 19. Well-Formed XML – Naming Styles • Pascal-casing <MyElement /> • Camel-casing <myElement /> • Underscored names <my_element /> • Hyphenated names <my-element />
  • 20. Well-Formed XML – Naming Specifications • can begin with either an underscore or an uppercase or lowercase letter from the Unicode character set • Subsequent characters can also be a dash (-) or a digit • Case-sensitive • the start and end tags must match exactly • cannot contain spaces
  • 21. Well-Formed XML – Naming Specifications - Examples
  • 22. Well-Formed XML – Naming Specifications - Examples
  • 23. Well-Formed XML – Exercise • <list><title>The first list</title><item>An item</list> • <item>An item</item><item>Another item</item> • <para>Bathing a cat is a <emph>relatively</emph> easy task as long as the cat is willing.</para> • <bibl><title>How to Bathe a Cat<author></title>Merlin Bauer<author></bibl>
  • 24. Well-Formed XML - Attributes
  • 25. Well-Formed XML - Attributes • name-value pairs associated with an element
  • 26. Well-Formed XML – Attributes - Rules • consist of a name and a value separated by an equals sign • The name follows the same rules as element names • The value must be in quotes • There must be a value part • Attribute names must be unique per element
  • 27. Well-Formed XML – Attributes - Examples
  • 28. Well-Formed XML – Attributes - Examples
  • 29. Well-Formed XML – Character content - Restrictions
  • 30. Well-Formed XML – Character content - Restrictions • Ampersand (&) • Left angle bracket (<)
  • 31. Well-Formed XML – Entity and Character References • There are two ways of inserting characters into a document that cannot be used directly – Entity references • Start with an ampersand (&) and finish with a semicolon (;) • There are five built-in entity references in XML – Character references • Begin with &# and end with a semicolon (;) • Example: the Greek letter omega (Ω) as a reference it would be &#x03A9; in hexadecimal or &#937; in decimal
  • 32. Well-Formed XML – Entity and Character References
  • 33. Well-Formed XML – Entity and Character References <!DOCTYPE myElement [ <!ENTITY copyright “© Wrox 2012”> ]>
  • 34. Well-Formed XML – Elements Versus Attributes
  • 35. Well-Formed XML – Elements Versus Attributes Rule ????
  • 36. Well-Formed XML – Elements Versus Attributes Attributes • There is only one piece of data • Names cannot be repeated • Make file size is smaller – Good to sent across network Elements • The data is not a simple type • Items may need to be repeated • Items can be ordered • A large amount of content that is just text
  • 37. Well-Formed XML – Elements Versus Attributes - Examples
  • 38. Well-Formed XML – Elements Versus Attributes - Examples
  • 39. Well-Formed XML – Processing Instructions • is used to communicate with the application that is consuming the XML – It is not used directly by the XML parser at all
  • 40. Well-Formed XML – CDATA • These are used as a way to avoid repetitive escaping of characters • Starts with <![CDATA[ and ends with ]]> • Example: you want data in your document 1 kilometer < 1 mile 1 pint < 1 liter 1 pound < 1 kilogram
  • 42. Well-Formed XML – CDATA • A common use of CDATA is in XHTML, the XML version of HTML
  • 43. Well-Formed XML – CDATA • A common use of CDATA is in XHTML, the XML version of HTML
  • 45. XML Namespaces – Example You need a new table Dining table Database table HTML table
  • 46. XML Namespaces • A way of grouping elements and attributes under a common heading in order to differentiate them from similarly-named items
  • 49. XML Namespaces – Why do you need namespaces? • You won’t always be using own XML formats entirely within your own systems
  • 50. XML Namespaces – How do you choose a namespace? • In Java, are called packages • In C#, are called namespaces – System.Windows.Forms.Timer – System.Timers.Timer – System.Threading.Timer
  • 51. XML Namespaces – How do you choose a namespace? • You can choose virtually any string of characters to make sure your element’s full name is unique • W3C recommend – URIs
  • 52. URLs, URIs, and URNs • URL is a Uniform Resource Locator, tells you the how and where of something – [Scheme]://[Domain]:[Port]/[Path]?[QueryString]#[Fra gmentId] – http://www.wrox.com/remtitle.cgi?isgn=0470114878 • URN is a Uniform Resource Name, is simply a unique name – urn:[namespace identifier]:[namespace specific string] – urn:isbn:9780470114872 • URI is a Uniform Resource Identifier, is URL or URN
  • 53. XML Namespaces – How to declare a namespace? • If you want all elements to be under the namespace – Declare a default namespace
  • 54. XML Namespaces – How to declare a namespace? • If you want specific elements to be under the namespace – Declare a namespace explicitly – Choose prefix to represent namespace • Some prefixes are reserved, such as xml, xmlns, and any other combinations beginning with the characters xml
  • 55. XML Namespaces – How to declare a namespace? Qualified Name (QName) Local Name
  • 56. XML Namespaces – How to declare a namespace?
  • 57. XML Namespaces – Declaring more than one namespace • <applicationUsers> element belongs to http://wrox.com/namespaces/applications/hr /config namespace • <user> elements belong to http://wrox.com/namespaces/general/entities namespace
  • 58. XML Namespaces – Declaring more than one namespace
  • 59. XML Namespaces – Declaring more than one namespace
  • 61. XML Namespaces – Real world • XML Schemas – Defining the structure of a document • Combination documents – Merging documents from more than one source • Versioning – Differentiating between different versions of an XML format
  • 62. XML Namespaces – Combination documents
  • 63. XML Namespaces – Versioning • Differentiating between different versions of an XML format • Go back to employees.xml – Namespace is http://wrox.com/namespaces/general/employee – Newer version: http://wrox.com/namespaces/general/employee/ v2
  • 64. XML Namespaces – Versioning How do I want the application to handle the two different versions?
  • 65. XML Namespaces – Versioning • Version one of the application opens a version one file • Version one of the application opens a version two file • Version two of the application opens a version one file • Version two of the application opens a version two file
  • 66. XML Namespaces – Versioning – Practical
  • 67. XML Namespaces – When to use and not use namespaces When namespaces are needed • When there’s no choice • When you need interoperability • When you need validation When namespaces are not needed • When you have the need to store or exchange data for relatively small documents that will be seen only by a limited number of systems
  • 68. XML Namespaces – Common namespaces • The XML Namespace http://www.w3.org/XML/1998/namespace – Attributes: • xml:lang • xml:space • xml:base • xml:id • xml:Father
  • 69. XML Namespaces – Common namespaces • The XMLNS Namespace http://www.w3.org/2000/xmlns/ • The XML Schema Namespace http://www.w3.org/2001/XMLSchema • The XSLT Namespace (xsl or xslt) http://www.w3.org/1999/XSL/Transform • The SOAP Namespace (soap, soap12) http://schemas.xmlsoap.org/soap/envelope/ (SOAP 1.1) http://www.w3.org/2003/05/soap-envelope (SOAP 1.2) • The WSDL Namespace (wsdl) http://www.w3.org/ns/wsdl (1.0, 2.0)
  • 70. XML Namespaces – Common namespaces • The Atom Namespace http://www.w3.org/2005/Atom • The MathML Namespace http://www.w3.org/1998/Math/MathML • The Docbook Namespace http://docbook.org/ns/docbook
  • 71. XML Namespaces – Exercise

Notas del editor

  1. Use for:Represent low-level data: ConfigurationAdd to metadata to documents: &lt;i&gt;, &lt;b&gt;Passing data between different components much easier
  2. -This means that the same underlying data can be used in multiple presentation scenarios. It alsomeans that when moving data, across a network for example, bandwidth is not wasted by havingto carry redundant information concerned only with the look and feelNameFolderBusiness, &lt; word 2003
  3. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  4. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  5. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  6. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  7. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  8. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  9. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  10. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  11. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  12. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  13. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  14. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  15. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  16. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  17. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  18. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  19. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  20. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  21. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  22. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  23. - when you’re designing an XML format for your own data so that you can be sure that any standard XML parser canhandle your document; when you are designing a system that will accept XML input from an external source so you’ll be sure that the data you receive is legitimate XML W3C’s XML Recommendation
  24. For a human reader this isn’t a problemIf asked to find the employee’s title, for example a report showing the title, first name, and last name, there could be a conflict because it can’t choose the correct title without further help
  25. For a human reader this isn’t a problemIf asked to find the employee’s title, for example a report showing the title, first name, and last name, there could be a conflict because it can’t choose the correct title without further help
  26. XML’s main purposes is to share data across systems and organizations
  27. Namespaces is that the declarations themselves look very much like attributes.
  28. Some prefixes are reserved, such as xml, xmlns, and any other combinations beginning with the characters xmlthis just means that you have a namespace URI that is identified by a prefi x of hr; so far none of the elements or attributes are grouped in that namespace. To associate the elements with the namespace you have to add the prefi x to the elements’ tags
  29. The reason for this is that attributes are always associated with an element; they can’t stand alone. Therefore, if the element itself is in a namespace,the attribute is already uniquely identifi able and there’s really no need for it to be a namespace
  30. Remember that the namespace declaration must come either on the element that uses it or on one higher in the tree, an ancestor as it’s often called.Picture 3: How exactly Does Scope Work?
  31. If version one of the software opens a version two fi le, would you expect it to be able to read it or not?Will it just ignore any elements it does not recognize and process the rest as normal, or just reject the fi le out of hand?If, however, you want the applications to be able to cope with both the earlier and the later formats it’s important that the two namespaces are the same. If this isn’t the case, the systems would need to know the namespaces of all possible future XML formats that could be accepted.
  32. When there’s no choice: if you choose to use a format designed by someone else to represent your data, the chances are that the format insists on the elements being in a namespace.When you need interoperability: “Do I need to share this data with other systems, particularly those not developed externally?”When you need validation: XML schema
  33. The prefix xml is bound to the URI http://www.w3.org/XML/1998/namespace and this is hard-coded into all XML parsers so you don’t need to declare it Yourselfxml:space: You met this in Chapter 2. It is used so the author of the document can specifywhether whitespace is signifi cant or not. It takes the values preserve or default.➤ xml:base: This is used in a similar way to the base attribute in HTML. It enables you tospecify a base URL from which any relative URLs in the document will be resolved.➤ xml:id: This specifies that the value of this attribute is a unique identifier within the document.➤ xml:Father: Although rarely seen in practice, its existence proves that the W3C’s XMLcommittee is actually human. It refers to Jon Bosak, a leading light in the XML communitywho chaired the original XML working group. It could be used, for example, when specifyinga document’s author such as &lt;document author=”xml:Father” /&gt;
  34. XMLNS: As you’ve seen throughout this chapter the xmlns prefix is used to declare a prefixed namespace in an XML document.XML Schema: is used in schema documents describing the legitimate structure of a particular XML formatXSLT: is primarily used to convert XML into a different format, either a differently-formatted XML or perhaps HTML or just plain textSOAP: It’s an XML format designed to enable method calls between a client and a web serviceWSDL: is used to describe a web service in such a way that clients can programmatically connect to a server, know what methods are available, and formattheir method calls appropriately
  35. Atom: is used for publishing information (such as newsfeeds) and has also been adopted by Microsoft for use in ODATAMathML is used to describe mathematical notations such as equations and their content and structureDocbook namespace is normally used to mark up such things as technical publications and software and hardware manuals