0% found this document useful (0 votes)
86 views7 pages

Myers

The document discusses XML and its advantages over HTML. XML is an open standard for defining markup languages that allows for any type of data, has a clear syntax, and unambiguous structure. It resembles HTML but is more flexible as tags can be user-defined. Well-formed XML documents follow syntax rules like being case-sensitive and requiring closing tags. Valid XML also conforms to a document type definition (DTD) that specifies allowed elements and attributes.

Uploaded by

api-3698136
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views7 pages

Myers

The document discusses XML and its advantages over HTML. XML is an open standard for defining markup languages that allows for any type of data, has a clear syntax, and unambiguous structure. It resembles HTML but is more flexible as tags can be user-defined. Well-formed XML documents follow syntax rules like being case-sensitive and requiring closing tags. Valid XML also conforms to a document type definition (DTD) that specifies allowed elements and attributes.

Uploaded by

api-3698136
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

What’s wrong with HTML?

XML ◆ Simple, but not powerful


C.R. Myers, Assistant Professor ◆ Tags pre-defined
School of Printing Management & Sciences ◆ Not strict about syntax
Rochester Institute of Technology ◆ Tags are formatting oriented

1 2

XML– eXtensible Markup Language What XML is NOT


◆ Open standard ◆ A replacement for HTML
◆ Any kind of data ◆ A programming language
◆ Unicode character set ◆ A network transport protocol
◆ Clear syntax ◆ A database
◆ Unambiguous structure

3 4

XML A sample XML file


◆ A language for creating markup languages <?xml version="1.0" ?>
◆ Resembles HTML or SGML <course>
◆ Tags, attributes and values <name>Doc. Proc. Lang.</name>
◆ DTD's
<number>2081-742</number>
<instructor>C.R. Myers</instructor>
◆ Portable data
<time>Tuesday, Noon - 2PM</time>
<time>Thursday, Noon - 2PM</time>
</course>

5 6

1
Conceptual structure XML entities
◆ less than = &lt; (<)
Course ◆ greater than = &gt; (>)
◆ quotation mark = &quot; (")
Name Number Instructor Time Time ◆ apostrophe = &apos; (')
◆ ampersand = &amp; (&)

7 8

XML syntax rules Tags are case-sensitive


◆ Tags are case sensitive <CourseName> is different from <coursename>
◆ Each document must have a root <Bad>This is bad XML</bad>
◆ Closing tags are required
◆ Values must be enclosed in quotation marks
◆ Elements must be properly nested
◆ Entities must be declared

9 10

XML documents must have a root Closing tags are required


<root> This is bad XML<p>
<child> This is also bad<br>
<subchild>
</subchild> <p>This is ok</p>
</child> This is the shortcut for an empty tag<br/>
</root>

11 12

2
Values must be in quotation marks Elements must be properly nested
<student id=1234>Bad Student!</student> <tag1><tag2>Badly nested!</tag1></tag2>
<student id="1234">Good Student</student> <tag1><tag2>Looks good!</tag2></tag1>

13 14

Attributes vs. Elements Attributes vs. Elements


Using an Element for gender: Using an Attribute for gender:
<person> <person gender="female">
<gender>female</gender> <firstname>Jane</firstname>
<firstname>Jane</firstname> <lastname>Doe<lastname>
<lastname>Doe<lastname> </person>
</person>

15 16

Attribute disadvantages Attributes still useful


◆ Can't contain multiple values ◆ Great for internal info, not needed by the user
◆ Not very expandable <messages>
◆ Can't describe structures <note id="123">Blah, blah, blah.</note>
◆ More difficult to manipulate <note id="124">More boring stuff</note>
◆ Hard to test against a DTD </messages>

17 18

3
Types of XML documents "Well-formed" XML
◆ Well-formed ◆ Follows the XML syntax rules
◆ Valid <?xml version="1.0"?>
<course>
◆ Invalid <name>Document Processing Languages</name>
<number>2081-742</number>
<college>CIAS</college>
<credits>4</credits>
<desc>Grad publishing technology</desc>
</course>

19 20

"Valid" XML Imbedded DTD


◆ A well-formed XML doc that conforms to a DTD <?xml version="1.0"?>
<!DOCTYPE name [
<?xml version="1.0"?>
<!DOCTYPE course SYSTEM "courses.dtd">
<course> definitions go here
<name>Document Processing Languages</name>
<number>2081-742</number> ]>
<college>CIAS</college> <root>
<credits>4</credits> </root>
<desc>Grad publishing technology</desc>
</course>

21 22

External DTD Parts of a DTD


<?xml version="1.0" standalone="no"?> Elements
<!DOCTYPE name SYSTEM "filename.dtd"> Attributes
<root> Entities
</root> PCDATA
CDATA

23 24

4
Declaring Elements in a DTD Declaring Elements in a DTD (cont’d)
General Form: <!ELEMENT name ANY>
Creates an element which can contain both
<!ELEMENT element-name element-rule> plain text and tags
element-name is the name of the tag you are defining <!ELEMENT name (#PCDATA)>
element-rule determines what content is legal in the tag Creates an element which can contain plain
text but NOT other tags
<!ELEMENT name EMPTY>
Creates an empty element

25 26

Declaring Elements in a DTD (cont’d) Declaring Elements in a DTD (cont’d)


<!ELEMENT name (child1, child2)> <!ELEMENT name (child)?>
Creates an element with children which Creates an element with a child which must
must be present in the order listed appear zero or one times
<!ELEMENT name (child1 | child2)> <!ELEMENT name (child)+>
Creates an element with options. Creates an element with a child which must
Either child1 or child2 must appear, but appear one or more times
not both. <!ELEMENT name (child)*>
Creates an element with a child which may
appear zero or more times

27 28

Declaring Attributes in a DTD Possible values for default


General form: #REQUIRED
<!ATTLIST target-element name type default> means that the value must be specified
#IMPLIED
target-element is the element to which the attribute means that the value is optional
applies
name is the attribute name
type is what type of data the attribute contains
default is whether the item is required

29 30

5
Legal types An XML Example
CDATA ◆ We will define a person like this:
Character data ◆ A person is required to be either male or female
◆ A person has a name which consists of:
◆ A first name
A list of values
◆ A last name
e.g. for marital status ◆ One (optional) nickname

(single | married | divorced | widowed) ◆ A person has an occupation


◆ A person has a description

31 32

An XML Example The “person” DTD


◆ We will define a person like this: <!ELEMENT person (name, occupation, description)>
<person gender=“male”> <!ELEMENT name (first, last, nickname?)>
<name> <!ELEMENT first (#PCDATA)>
<first>Charles</first> <!ELEMENT last (#PCDATA)>
<last>Myers</last> <!ELEMENT nickname (#PCDATA)>
<nickname>C.R.</nickname>
<!ELEMENT occupation (#PCDATA)>
</name>
<occupation>college professor</occupation> <!ELEMENT description (#PCDATA)>
<description>bald geek</description> <!ATTRIBUTE person gender (male | female) #REQUIRED>
</person>

33 34

What's wrong with DTD's XML Schema


◆ DTD’s use old SGML style definitions ◆ XML definition system developed to replace
◆ DTD are not written in XML Document Type Definitions

35 36

6
Other related technologies Transforming XML
◆ CSS - Cascading Style Sheets for display ◆ XSLT
◆ Extensible Stylesheet Language - Transformations
◆ XSL - Extensible Stylesheet Language for display
◆ Can convert XML to other languages
◆ XSLT - XSL Transformations ◆ SGML
◆ Xpath - Allows XML files to include other content ◆ HTML
◆ PDF
◆ Xlink - Allows XML files to link to other XML files
◆ PostScript
◆ Xquery - Allows XML files to query databases ◆ Just about anything else

37 38

You might also like