XML Development - PowerPoint PPT Presentation

1 / 32
About This Presentation
Title:

XML Development

Description:

Every attribute of each element must be declared. ... REQUIRED indicates the attribute must always be present ... indicates a default value for an attribute ... – PowerPoint PPT presentation

Number of Views:18
Avg rating:3.0/5.0
Slides: 33
Provided by: chuck68
Category:

less

Transcript and Presenter's Notes

Title: XML Development


1
XML Development
2
XML, HTML, SGML,
SGML
  • HTML was derived from SGML for Web displays. It
    is not
  • Extensible (You cant make your own tags.)
  • Structured (You cant define types of data.)
  • Descriptive (Fixed Head, Body, and thats all.)
  • Validating (Theres no way to test your data for
    valid representation.)

HTML
XML
  • XML, also a derivative of SGML, allows better
    handling of data

3
What Is XML (and, of course, what is it not)?
  • XML (eXtensible Markup Language) is a markup
    language, like HTML, that allows relatively easy
    transfer of information via a Web page.
  • You still need HTML for traditional Web
    pages!!!!! HTML is
  • Faster
  • Easier
  • Smaller

4
Why You Should Learn XML
  • XML is a new technology
  • MIS managers need to understand technology
  • If I offered to set you up with a Web-based EDI
    system using XML for 50,000, is that a good deal
    or a bad deal?
  • Evaluation of some MIS managerial questions
    require that you have a somewhat-deep
    understanding of the underlying technology

5
Format for XML
  • Valid XML requires several elements
  • An XML file for data and tags
  • A DTD (Document Type Definition) file to define
    meaning to the tags
  • Possibly, an XSL file for formatting.

Invoice.xml
Invoice.dtd
Invoice.xsl
6
Well-formed XML
  • You define your own element tags
  • Every element tag has an ending tag or terminator
  • Attributes are in quotes
  • XML is case sensative!!!
  • Well-formed XML is not necessarily valid XML
  • XML consists mainly of
  • element tags
  • attributes.

Element
Attribute
ltclass idMGT463"gt ltsection id"001"gt ltinstructor
name"Chuck Wood id1234"/gt ltstudentgtJoe
Studentlt/studentgt ltstudentgtJane
Studentlt/studentgt lt/sectiongt lt/classgt
Terminator
Ending Tag
7
XML Comments
  • Like HTML, XML uses a lt! tag for a comment
  • lt!-- This is a comment. --gt
  • Be sure to comment your code (so I know what you
    were trying to do)!!!

8
XML Processing Instructions
  • Processing instructions (PIs) allow XML documents
    to contain instructions for application, using
    the lt? Tag
  • Often, the only processing instruction in an XML
    document is used to describe the XML version
    used
  • lt?xml version"1.0" ?gt

9
Whats It Look Like in IE 5.0?
In IE 5.0, XML defaults to display as a tree
document.
10
DTDs and Valid XML
  • XML is well-formed when attributes are in quotes
    and every tag is terminated
  • Well-formed XML is not necessarily valid XML.
  • A DTD is used to define each possible element
    inside a valid XML file
  • Each element must be declared.
  • Each element needs a data type.
  • Each cardinal relationship (one to many, one to
    one, etc.) between elements must be declared.
  • Every attribute of each element must be declared.

DTDs allow a shared language between those with
shared interests
11
The Importance of DTDs
DTDs are extremely important. Companies can use
DTDs to develop a standard language with each
others XML. Several scientific, educational,
and financial industries have already defined
DTDs that are available so different companies
can communicate with each other through XML. XML
requires a DTD to be valid. XML will not (and
should not) work without this type of document.
12
FIXML XML for Financial Information Exchange
How long before the SEC requires electronic
transfer of all 10K information? FIXML allows
the transfer of financial data.
13
FpML Financial Products Markup Language
FIXML may have some competition. FpML allows the
easy transfer of financial products data.
14
Chemistry Markup Language -- CML
Having a common language is vital to Web-EDI
within industries. The Food and Drug
Administration (FDA) and the Oak Ridge National
Laboratory have developed a chemistry DTD called
CML. Elements like ltATOMSgt, ltMOLgt (for
molecule), ltBONDSgt, ltMOLEgt, and ltFORMULAgt are
defined.
15
XML and Wireless Markup Language (WML)
WAP (Wireless Application Protocol) uses WML to
transmit data to wireless devices. Many view
wireless communication to be the backbone of B2B
and B2C electronic commerce.
16
DTDs for Dessert?
A common language for hobbies? Ya gotta eat,
right? Why not have a DTD that allows easy
transfer of recipies, like this one?
17
DTDs for Dissertations
This one is, of course, near and dear to my heart
18
A DTD for (more than) Everyone
XML is relatively new, but already there seems to
be more XML DTD specifications than there are
Washington lobbyists. Let the fight for
standards begin!
19
Tying XML to a DTD
  • DTDs typically exist in a separate file.
  • To access this file within XML, just add a
    DOCTYPE command with the lt! tag

lt?xml version"1.0" ?gt lt!-- student.xml
--gt lt!DOCTYPE class SYSTEM "student.dtd"gt ltclass
id"IDSc6442"gt ltsection id"001"gt ltinstructor
name"Chuck Wood id1234"/gt ltstudentgtJoe
Studentlt/studentgt ltstudentgtJane
Studentlt/studentgt lt/sectiongt lt/classgt
DTD File
20
Valid XML and DTDs
A DTD, like this DTD used with the class XML in
the previous slide, is necessary to change
well-formed XML into valid XML
  • DTDs are required for valid XML.
  • Every XML tag needs to be defined in the DTD file

lt?xml version"1.0" encoding"UTF-8" ?gt lt!--
student.dtd --gt lt!ELEMENT class (section) gt
lt!ATTLIST class id ID REQUIREDgt lt!ELEMENT
section (instructor?, student)gt lt!ATTLIST
section id ID REQUIREDgt lt!ELEMENT
instructor EMPTYgt lt!ATTLIST instructor name
CDATA REQUIRED id ID IMPLIEDgt lt!ELEMENT
student (PCDATA)gt
21
DTD Language Structures
  • DTDs consist of two basic structures
  • Elements are tags that you define in your XML.
  • Attributes are part of elements. They allow you
    to describe an element more fully.
  • Relationship between elements can be defined
  • Entities can also be defined, but are rarely used
    (and not addressed much in this class.

22
Entities (Our First and Last Coverage of XML
Entities)
  • Entities are probably misnamed. They are not
    often used and define some text or a file that is
    important. Consider the trademark entity below
  • lt!ENTITY trademark SYSTEM "http//www.chuckwood.c
    om/trademark.xml"gt
  • This allows XML to incorporate file information
    by using a trademark tag. Entities can be used
    to define certain constants to be used in XML
    pages.

23
Elements
  • An XML lt!ELEMENT tag defines an element tag
    allowable in XML.
  • XML Elements can be one of three types, as
    demonstrated by DTD coding of HTML tags
  • Elements to be terminated immediately, such as
    the ltBRgt HTML tag
  • lt!ELEMENT BR EMPTYgt
  • Elements that have corresponding child elements,
    such as the ltTRgt HTML tag
  • lt!ELEMENT TR (TH, TD)gt
  • Elements that have text, usually character data,
    such as the ltH1gt HTML tag
  • lt!ELEMENT H1 (PCDATA)gt

24
Element-to-Element Cardinality
  • You can establish cardinal elemental
    relationships in a DTD. For example, consider
    the red operators in the following DTD
  • lt!ELEMENT section (room, instructor?, student)gt
  • The ? and indicate cardinal relationships
  • ? indicates one-to-zero or one
  • (blank) indicates one-to-one
  • indicates one-to-zero or more
  • indicates one-to-one or more

This XML states that each section has no or one
instructor, and zero or more students.
25
Element Order
  • DTD allows you to force a specific element order
    inside your XML document. The following DTD
  • lt!ELEMENT section (room, instructor?, student)gt
  • forces room, instructor, and students to be
    declared in that order
  • Use the pipe operator () instead of a comma to
    allow declaration in any order
  • lt!ELEMENT section (room instructor? student)gt

26
Declaring No Cardinality
  • You signify that an element has no relationships
    to any other element using the EMPTY DTD
    attribute
  • lt!ELEMENT instructor EMPTYgt
  • The instructor element is allowed to have
    attributes, but can have no text or subordinate
    XML element tags
  • ltinstructor name"Chuck Wood"/gt
  • or
  • ltinstructor name"Chuck Wood"gtlt/instructorgt

27
PCDATA
  • Declaring PCDATA as a child type allows text to
    be entered between a tag and its ending tag.
  • The following DTD code
  • lt!ELEMENT student (PCDATA)gt
  • allows the following XML
  • ltstudentgtJohn Doelt/Studentgt
  • Without PCDATA, no text (e.g., John Doe) would
    be allowed to be entered between the starting and
    ending tags.

28
XML Attributes
  • XML attributes are attributes that are placed
    within tags
  • ltinstructor name"Chuck Wood" id"1234"/gt
  • Attributes are defined in an attribute list in
    the DTD using the lt!ATTLIST directive
  • lt!ELEMENT instructor EMPTYgt
  • lt!ATTLIST instructor
  • name CDATA REQUIRED
  • id ID IMPLIEDgt

29
Attribute Types
  • There are several different attribute types, but
    two are particularly important
  • CDATA Allows any character or alphanumeric data
  • ID Forces a unique value of an attribute

For a complete list, if you want one, check out
W3Cs document definition markup language at
http//www.w3.org/TR/NOTE-ddml.
30
Attribute Restrictions
  • Each attribute declaration provides information
    in whether the attributes presence is required
  • REQUIRED indicates the attribute must always be
    present
  • IMPLIED indicates that the attribute need not be
    present
  • Default value indicates a default value for an
    attribute
  • FIXED default value indicates that the attribute
    must always have a specific value

31
Designing DTDs and XML
  • The subject of how to design a DTD has come up
    quite frequently specifically, what are
    attributes vs. what are child elements?
  • The most common response is that you should use
    object-oriented design techniques
  • Entities in the OO design should be classified as
    XML elements.
  • Attributes in the OO design should become
    attributes in XML.

32
Things you should know
  • Many tools (like IE 5.0, Microsoft DOM) have the
    capability to parse invalid, but well-formed XML.
  • Never transmit invalid XML (XML without a DTD)!!!
  • DTDs are important in developing a shared
    language between partners, and for debugging bad
    XML.
  • XmL iS CaSe SenSAtive!!!
  • TIP Many sites use lower case only for their
    tags. Its easier.
Write a Comment
User Comments (0)
About PowerShow.com