You will be able to create a simple XML document
You will be able to identify the componets of well formed XML document
.You will be able to identify the difference between well formed and valid XML documents
Read: Chapter 1 & 2
You need to read the W3schools XML Elements, Attributes, & DTD tutorials!
Well formed vs Valid:
Well formed mean the XML document follows proper XML syntax!
Valid means the document is well-formed and follows the structure defined in a DTD or Schema
Create a Fake XML Resume & XML Address book for posting next week.
Syntax Rules
XML documents must start with <?xml version="1.0"?> or <?xml version="1.0" encoding="ISO-8859-1"?> to be well formed.
Typical XML encoding ISO-8859-1 or UTF-8 or UTF-16 defines the characters used within the document
XML Elements are Extensible (expandable) but must follow these rules
All XML Elements Must Have a Closing Tag!
- Names cannot start with a number or punctuation character
- Names can contain letters, numbers, and other characters
- Names cannot start with the letters xml (or XML, or Xml, etc)
- Names cannot contain spaces
XML Elements are Case Sensitive<element> info </element> or <element />
XML Attributes Must be Quoted<element> is different from <Element>
<element>This is not closed so the code is </Element>
<element>This is correct</element><info name="Jon"> or <info name='Jon'>
Attribute values must always be quoted. Either single or double quotes can be used.
Please Note: There are no rules about when to use attributes or when to use elements. I would avoid them and use elements instead
XML Elements Must be Properly Nested
<jon> <tom> </jon> </tom> is not nested properly
<jon> is nested </jon>
<tom>properly</tom>Element Content can not contain &, >, <, ", ', instead use:
& for &
> for >
< for <
" for "
and ' for 'Practice:
Create an XML file of your family tree (go back at least 2 generations) We will go over this next week!
You need a DTD or a Schema to Validate an XML Document:
Schema uses XML to define an XML document.
DTD use a separate language for defining the structure of an XML document
DTD Info:
DTD = Document Type Definition is used to define the structure you want the document to follow. DTD use a separate language to define the structure the XML should follow. You can have an internal or external DTD
Internal DTD Reference: <!DOCTYPE RootElement [
See nba-dtd.xml for a simple example of an internal DTD<!ELEMENT name category> for defining Elements
<!ATTLIST element-name attribute-name attribute-type default-value > for defining Attributes of Elements
...
]>
External DTD Reference: <!DOCTYPE RootElement SYSTEM "filelocation">
The external DTD is a separate document with the following syntax:
You need only the Element and Attritbute references in the document!
<!ELEMENT name category> for defining Elements
<!ATTLIST element-name attribute-name attribute-type default-value > for defining Attributes of Elements.
See nba.dtd for a simple example of an External DTD
Practice
Create a DTD for these two files: Me and Me2 (We will review this next class)Terms:
Summary of Syntax
XML Rules for Well formness | Element Name Rules |
---|---|
<?xml version=“1.0” ? > | Names can not start with numbers! |
XML |
Names can start with letters or _ (under-bar) |
<Start> </Start> or <Start /> You start a tag, you must end it in some format |
No Spaces for element names ! |
Elements Are Case Sensitive!! <start> is not the same as <Start> |
Can Not Start with XML |
<!-- Comment --> | No Space after the start of a tag < |
XML Keeps White Space Tag Order Counts |
Remember the difference:
XML with correct syntax is a "Well Formed" XML document.
XML is validated against a DTD or Schema