The Rules of XML
2 sets of Rules
Set 1 -> Is the XML Well-Formed?
1) All XML Documents have a "root" element,
everything else in inside the root element
in XML elements (tags) are: <...>
2) Every element (tag) must start and end
... <- a closing tag
or
<- a self-closing tag
3) Elements (everything in XML) is case sensitive
... <- correct
... <- fails
4) Attributes (Meta information, information about the element)
go in the start tag only, and must have name '=' value
the value must be in quotes
123.45 <- Ok, but what is the currency?
123.45
5) Element must nest correctly, the order the elements are opened
defines the order the elements are closed
(last one opened, is the first one closed)
Set 2 -> Does the XML meet the Business Rules: Valid?
A) I can write rules for stucture only: DTD
Used for HTML, where I care about the structure, but
content is up to you
B) I can write rules for structure and content: Schema
Used in SOAP Web Services (what do you pass to the Web Service
and whet the Web Services returns to you)
An XML Schema defines structue and content:
the Structure is in the form of Elements,
a/ sequence, complexTypes
the Contents is in the form of XML Data Types
NOTE: NOT JAVA
the W3C defines the XML rules, and defines the
XML Schema Data Types
https://www.w3.org/standards/xml/schema
https://www.w3.org/TR/xmlschema-2/
-----------------------------------------------
XML Document can be build in "parts"
for example, part of my document is from the HR dept,
part of my document is from purchasing,
part of document is from sales.
How do I tell which part are from where,
and which schemas are used for wich parts?
for each element or attribute in the XML I have a
NameSpace <- this is an ID to tie that element/attribute
to a specific schema
In XML a NameSpace is defined as:
xmlns:=.....
xmlns:xsd=""
A NameSpace is a URI not a URL, because NameSpace are unique
we (mostly) use our Internet name as part of it