XML eXtensible Markup Language - PowerPoint PPT Presentation

1 / 46
About This Presentation
Title:

XML eXtensible Markup Language

Description:

XML eXtensible Markup Language by Darrell ... More Comments -- XML Validator Create XML Document 3 Create root element Create child element of session1 ... – PowerPoint PPT presentation

Number of Views:107
Avg rating:3.0/5.0
Slides: 47
Provided by: Darr116
Category:

less

Transcript and Presenter's Notes

Title: XML eXtensible Markup Language


1
XML eXtensible Markup Language
  • by Darrell Payne

2
Experience
  • Logicon / Sterling Federal
  • C, C, JavaScript/Jscript, Shell Script, Perl
  • XML Training
  • XML Training Course
  • 2001 DevXCon Training Conference
  • Currently developing XML course for Logicon
  • Darrell.Payne_at_Sterling-fsg.com

3
XML eXtensible Markup Language
  • Standard General Markup Language(SGML)
  • Meta-tag language
  • Used for creating other markup languages
  • Standard adopted for SGML in 1986
  • Hyper Text Markup Language(HTLM)
  • Application of SGML
  • Formatting Language
  • eXtensible Markup Language(XML)
  • Meta-tag language
  • XML DATA
  • World Wide Web Consortium W3C
  • ((!Standard) (Specification)) // c code
    humor
  • XML Version 1.0 February 1998
  • XML is not designed to replace HTML

4
SGML HTML XML diagram
5
XML Family of Tools and Their Relationship
Linking and Pointing
Style and Transformation
Underlying And Object Model
Complex Data Modeling
Programmatic Interface
XML Developer's Guide - McGraw Hill - Page 12
6
HTML vs. XML
  • Html
  • Predefined tags
  • Syntax is loose
  • File extensions usually .html of .htm
  • Not required to be Well Formed
  • Some closing tags optional
  • Attribute value quotes may be omitted
  • XML
  • User defined tags
  • Syntax is exact
  • File extensions usually .xml
  • Closing tags mandatory
  • Required to be Well - Formed

7
Well - Formed
  • All XML documents must be Syntactically correct!
  • Single root element
  • All element start tags have end tags
  • XML is case sensitive
  • Properly nested tags
  • ltfirstgtltsecondgtlt/firstgtlt/secondgt //error
  • ltfirstgtltsecondgtlt/secondgtlt/firstgt //correct
  • Attributes values in quotes
  • value or value

8
Basic XML Parts
  • Markup
  • Tags
  • Attributes, names and values
  • Character Data
  • Text
  • PCDATA
  • CDATA
  • Binary
  • XML document has two main sections
  • Prolog
  • Root
  • Misc
  • Optional and considered superfluous

9
Simple XML File
  • lt?xml version"1.0"?gt
  • lt!-- My first XML file --gt
  • ltdocumentgt
  • ltmessagegtHello World!lt/message gt
  • lt/document gt
  • lt!--
  • More Comments
  • --gt

10
Declaration
  • If used
  • lt?xml version"1.0"?gt required
  • Declaration optional
  • Specifies version to which document conforms
  • XML documents without XML declaration might be
    assumed to conform to the latest version
  • Other declaration examples
  • lt?xml version"1.0" encoding"UTF-8"?gt optional
  • Default Good for ASCII text 8 bit characters
  • UTF-16 Good for foreign 16 bit characters
  • Used for Unicode characters
  • To stay uniform use with 8 or 16
  • lt?xml version"1.0" standalone"yes"?gt optional
  • No external subset referenced default
  • lt?xml version"1.0" encodingUTF-8
    standalone"yes?gt

11
Comments
  • lt!-- My first XML file --gt
  • lt!--
  • More Comments
  • --gt
  • XML uses same comment syntax as HTML

12
Root Element
  • ltdocumentgt
  • lt/documentgt
  • Lines preceding root element are contained in the
    Prolog
  • All XML documents must contain only one root
    element
  • All other elements are child elements

13
Child Element
  • ltdocumentgt
  • ltmessagegtHello World!lt/message gt
  • lt/document gt

14
Sibling Element
  • ltdocumentgt
  • ltmessagegtHello World!lt/message gt
  • ltmessagegtGoodbye World!lt/message gt
  • ltmessage2gtNothing more to add!lt/message2 gt
  • lt/document gt

15
Updating Microsofts Internet Explorer
  • instmsia.exe
  • Updates Microsofts Installer
  • msxml3sp1.exe
  • Updates Microsofts Internet Explorer
  • IE now has built-in XML parser msxml

16
Create XML Document
  • Include declaration
  • lt?xml version"1.0"?gt
  • Create root element ltcis_classgt
  • Create child element ltcis_345gt
  • Enter child element text student name
  • Save file with .xml extension
  • Open using Internet Explorer
  • After success, add siblings elements and retest
    using Internet Explorer

17
Document viewed in Microsoft's Internet Explorer
18
More about Elements
  • Element types
  • Container Element
  • Contains other elements
  • Data Element
  • Contains DATA
  • Mixed Content
  • Contains other elements and DATA
  • Empty Element
  • Contains no elements or DATA

19
Container Element
  • Contains other elements
  • ltouter_elementgt
  • ltinner_elementgt
  • ltyet_another_elementgt
  • ltcan_we_go_any_deepergt
  • Some text way down here in the center of it all
  • lt/can_we_go_any_deepergt
  • lt/yet_another_elementgt
  • lt/inner_elementgt
  • lt/outer_elementgt

20
Data Element
  • Contains DATA
  • Parsable Character Data
  • PCDATA
  • Character Data
  • CDATA

21
PCDATA
  • Contains text
  • Can be parsed by parser
  • Can contain all text except
  • lt
  • gt

22
Entity References
  • XML provides built in entity references
  • lt
  • gt
  • quot
  • apos
  • amp

23
CDATA
  • Contains text
  • Is a declaration
  • Can contain reserved characters
  • lt, gt, , ,
  • Starts with / ends with
  • lt!CDATA
  • Data would be here
  • gt
  • CDATA can not contain
  • gt

24
Declarations
  • lt!-- --gt
  • lt!DOCTYPE gt
  • lt!CDATA gt
  • lt!ELEMENT gt
  • lt!IGNORE gt
  • lt!INCLUDE gt
  • lt!NOTATION gt
  • lt!ENTITY gt
  • lt!ATTLIST gt

25
Why CDATA section
  • C code example
  • CDATA example
  • If (this-gtgetX() lt 5 array10 ! 3)
  • cerr ltlt this-gtdisplayError()
  • PCDATA example
  • If (this-gtgetX() lt 5 ampamp array10
    ! 3)
  • cerr ltlt this-gtdisplayError()

26
Mixed Content
  • Elements and PCDATA combined
  • ltouter_elementgt
  • outer element stuff
  • ltinner_elementgt
  • inner element stuff
  • lt/inner_elementgt
  • more outer element stuff
  • lt/outer_elementgt

27
Empty Element
  • Contains no text or data
  • May have an attribute
  • ltempty_elementgtlt/empty_elementgt
  • ltempty_element/gt
  • Short cut notation for empty element
  • Does this look unfamiliar
  • HTML example of such a type of tag
  • ltimg src image.gifgt //Non Well Formed
  • ltimg src image.gif /gt //Well Formed

28
Elements
29
Create XML Document 2
  • Include declaration
  • Create root element ltcis_class2gt
  • Create child element ltcis_345gt
  • Enter child element text student name
  • Create child element ltcis_346gt
  • Child to root, sibling to ltcis_345gt
  • Make this an empty element
  • Create child element ltcis_347gt
  • Child to root, sibling to ltcis_345gt
  • Enter C code example in PCDATA section
  • Create child element ltcis_348gt
  • Enter same C code in a CDATA section
  • Save file
  • Open using Internet Explorer

30
XML Parser DOM SAX
  • Required to process an XML document
  • C, Java, Python, Perl
  • Parsers are of type
  • Document Object Model(DOM)
  • Tree structure
  • Like a drive directory structure
  • Slower and requires large amounts of memory
  • Simple API for XML(SAX)
  • Events driven
  • Events tags, text, etc.
  • Smaller, faster, but requires programmer to deal
    with data
  • Validating and non-validating

31
XML Structure
  • Logical structure
  • Document divided into units
  • Allows sub units
  • XML is a logical tree structure document
  • Physical structure
  • Data stored inside document
  • Data stored outside document
  • Entities one example

32
Valid
  • Conforms to some schema
  • schema s
  • Document Type Definition(DTD)
  • Schema
  • By definition, all valid XML documents are Well
    Formed documents

33
DTD Document Type Definition
  • Document Type Declaration(DTD)
  • File extension of .dtd
  • DTD is not an XML document
  • DTD is a schema s
  • Introduced into an XML document via the Document
    Type Declaration
  • lt!DOCTYPE gt
  • Three types of DOCTYPE declarations
  • Internal Subset
  • Contained in the Prolog
  • External Subset
  • Exist in different file
  • Prolog contains reference to file containing DTD
  • Referenced using key work
  • SYSTEM or PUBLIC
  • Internal Subset and External Subset combination

34
Internal Subset
  • lt?xml version"1.0"?gt
  • lt!-- My second XML file --gt
  • lt!DOCTYPE document
  • lt!ELEMENT document (message)gt
  • lt!ELEMENT message (PCDATA)gt
  • gt
  • ltdocumentgt
  • ltmessagegtHello World!lt/messagegt
  • lt/documentgt
  • lt!--
  • More Comments
  • --gt

35
External Subset
  • lt?xml version"1.0"?gt
  • lt!-- My second XML file --gt
  • lt!DOCTYPE document SYSTEM "HelloWorld.dtd"gt
  • ltdocumentgt
  • ltmessagegtHello World!lt/messagegt
  • lt/documentgt
  • lt!--
  • More Comments
  • --gt

36
DTD for HelloWorld.xml
  • lt!ELEMENT document (message)gt
  • lt!ELEMENT message (PCDATA)gt

37
Internal Subset and External Subset combination I
  • lt?xml version"1.0"?gt
  • lt!-- My second XML file --gt
  • lt!DOCTYPE document SYSTEM "HelloWorld3.dtd"
  • lt!ELEMENT document (message)gt
  • gt
  • ltdocumentgt
  • ltmessage gt
  • ltmessage2gt
  • lt/message2gt
  • lt/messagegt
  • lt/documentgt
  • lt!--
  • More Comments
  • --gt

38
Internal Subset and External Subset combination II
  • lt!-- External declarations --gt
  • lt!ELEMENT message (message2)gt
  • lt!ELEMENT message2 (PCDATA)gt

39
Putting it all together
  • HelloWorld3.dtd
  • lt!-- External declarations --gt
  • lt!ELEMENT message (message2)gt
  • lt!ELEMENT message2 (PCDATA)gt
  • HelloWorld3.xml
  • lt?xml version"1.0"?gt
  • lt!-- My second XML file --gt
  • lt!DOCTYPE document SYSTEM "HelloWorld3.dtd"
  • lt!ELEMENT document (message)gt
  • gt
  • ltdocumentgt
  • ltmessage gt
  • ltmessage2gt
  • lt/message2gt
  • lt/messagegt
  • lt/documentgt
  • lt!--
  • More Comments
  • --gt

40
XML Validator
Type in HelloWorld3.xml
41
Create XML Document 3
  • Create root element ltsession1gt
  • Create child element of session1ltsession2gt
  • Enter child element text xml class
  • Create child element of session2ltsession3gt
  • Enter child element text class information
  • Create child element of session3ltsession4gt
  • Enter child element text more
  • Create DTD for this file dtd_info.dtd
  • Reference file in XML document
  • Save files
  • Open validate_vbs.html
  • Enter .xml file name
  • Validate

42
Schema
  • Schemas are XML documents
  • Schemas can be manipulated via a parser
  • More complicated than DTDs
  • Schemas have ElementTypes

43
Schema vs. DTD
  • lt!-- External declarations --gt
  • lt!ELEMENT document (message, message2, message3)gt
  • lt!ELEMENT message (message4, message5 )gt
  • lt!ELEMENT message2 (PCDATA)gt
  • lt!ELEMENT message3 (PCDATA)gt
  • lt!ELEMENT message4 (PCDATA)gt
  • lt!ELEMENT message5 (PCDATA)gt

44
Schema vs. DTD II
  • lt?xml version"1.0" encoding"UTF-8"?gt
  • lt!--W3C Schema generated by XML Spy v3.5
    (http//www.xmlspy.com)--gt
  • ltxsdschema xmlnsxsd"http//www.w3.org/2000/10/X
    MLSchema" elementFormDefault"qualified"gt
  • ltxsdelement name"document"gt
  • ltxsdcomplexTypegt
  • ltxsdsequencegt
  • ltxsdelement ref"message"/gt
  • ltxsdelement ref"message2"/gt
  • ltxsdelement ref"message3"/gt
  • lt/xsdsequencegt
  • lt/xsdcomplexTypegt
  • lt/xsdelementgt

45
Schema vs. DTD III
  • ltxsdelement name"message"gt
  • ltxsdcomplexTypegt
  • ltxsdsequencegt
  • ltxsdelement ref"message4"/gt
  • ltxsdelement ref"message5"/gt
  • lt/xsdsequencegt
  • lt/xsdcomplexTypegt
  • lt/xsdelementgt
  • ltxsdelement name"message2" type"xsdstring"/gt
  • ltxsdelement name"message3" type"xsdstring"/gt
  • ltxsdelement name"message4" type"xsdstring"/gt
  • ltxsdelement name"message5" type"xsdstring"/gt
  • lt/xsdschemagt

46
Topics not covered
  • Namespace Whitespace
  • Xpath Xpointer
  • Xlink
  • XSL XSLT
  • SOAP DDI
  • Web Services
  • SMIL
  • XHTML
Write a Comment
User Comments (0)
About PowerShow.com