Logical Structure of XML Documents

Download Report

Transcript Logical Structure of XML Documents

Introduction to the Logical
Structure of XML Documents
Web Engineering, SS 2007
Tomáš Pitner, Michael Derntl
Example of an XML Document
<?xml version='1.0' encoding='UTF-8'?>
<staff organization="Bundesregierung">
<person id="agu">
<name>Alfred Gusenbauer</name>
<party url="http://www.spoe.at">SPÖ</party>
</person>
<person id="wmo">
<name>Wilhelm Molterer</name>
<party url="http://www.oevp.at">ÖVP</party>
</person>
</staff>
XML Document – Prolog/Heading
<?xml version='1.0' encoding='UTF-8'?>
<staff organization="Bundesregierung">
<person id="agu">
Version:
<name>Alfred Gusenbauer</name> Character
typically 1.0
encoding: UTF<party url="http://www.spoe.at">SPÖ</party>
8, UTF-16, US</person>
XML
Prolog
ASCII always
<person id="wmo">
work!
<name>Wilhelm Molterer</name>
<party url="http://www.oevp.at">ÖVP</party>
</person>
</staff>
XML Document - Root Element
<?xml version='1.0' encoding='UTF-8'?>
<staff organization="Bundesregierung">
<person id="agu">
<name>Alfred Gusenbauer</name>
<party url="http://www.spoe.at">SPÖ</party>
</person>
<person id="wmo">
<name>Wilhelm Molterer</name>
Root element contains most
<party url="http://www.oevp.at">ÖVP</party>
</person>
</staff>
of the information in the doc,
every doc must have exactly
one root element!
Elements and Tags
Element
Element
Name
<?xml version='1.0'
encoding='UTF-8'?>
<staff organization="Bundesregierung">
<person id="agu">
<name>Alfred Gusenbauer</name>
<party url="http://www.spoe.at">SPÖ</party>
</person>
<person id="wmo">
Start Tag of the element
<name>Wilhelm Molterer</name>
<party url="http://www.oevp.at">ÖVP</party>
</person>
</staff>
End Tag of the element
Attributes
Attribute: placed in the
<?xml
version='1.0'
encoding='UTF-8'?>
element's
start tag
<staff organization="Bundesregierung">
<person id="agu">
<name>Alfred Attribute
Gusenbauer</name>
Value: in single or double quotes!
<party url="http://www.spoe.at">SPÖ</party>
</person>
<person id="wmo">
Note: multiple Attributes are
separated through whitespace
<name>Wilhelm Molterer</name>
<party url="http://www.oevp.at">ÖVP</party>
</person> Attribute Name: unique
</staff>
within an element!
Element Content: Text Nodes
<?xml version='1.0' encoding='UTF-8'?>
<staff organization="Bundesregierung">
<person id="agu">
<name>Alfred Gusenbauer</name>
<party url="http://www.spoe.at">SPÖ</party>
Element
</person>
<person id="wmo">
<name>Wilhelm Molterer</name>
<party url="http://www.oevp.at">ÖVP</party>
</person>
</staff>
Element Content: Text Node
Element Content: Child Elements
(Parent)
<?xml Element
version='1.0' encoding='UTF-8'?>
<staff organization="Bundesregierung">
<person id="agu">
<name>Alfred Gusenbauer</name>
<party url="http://www.spoe.at">SPÖ</party>
</person>
<person id="wmo">
<name>Wilhelm Molterer</name>
<party url="http://www.oevp.at">ÖVP</party>
</person>
</staff>
Element Content: Child Elements
XML Document with DTD
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE staff SYSTEM "staff.dtd">
<staff organization="Bundesregierung">
<person id="agu">
<name>Alfred Gusenbauer</name>
Root element
System identifier
<party url="http://www.spoe.at">SPÖ</party>
name
</person>
<person id="wmo">
(URI) of the
entity/file with
<name>Wilhelm Molterer</name>Document Type
<party url="http://www.oevp.at">ÖVP</party>
Definition
</person>
</staff>
Document Type
Declaration
XML Document with Comment
<?xml version='1.0' encoding='UTF-8'?>
<!-- Comment content -->
<!DOCTYPE staff SYSTEM "staff.dtd">
<staff organization="Bundesregierung">
<person id="agu">
Comment
<name>Alfred Gusenbauer</name>
content
<party url="http://www.spoe.at">SPÖ</party>
</person>
<person
Commentid="wmo">
(-node):
<name>Wilhelm Molterer</name>
usually
not interpreted
<party url="http://www.oevp.at">ÖVP</party>
by the application
</person>
</staff>
Processing Instructions
<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet href="style.css" type="text/css"?>
<!DOCTYPE staff SYSTEM "staff.dtd">
<staff organization="Bundesregierung">
<person id="agu">
PI Target
PI Data (no attributes!)
<name>Alfred
Gusenbauer</name>
<party url="http://www.spoe.at">SPÖ</party>
</person>
<person id="wmo">
<name>Wilhelm Molterer</name>
<party url="http://www.oevp.at">ÖVP</party>
</person>Instruction:
Processing
</staff>
interpretation depends on
application