570 likes | 683 Views
IAD 303 XML Primer. Scott McReynolds Product Line Specialist IAD scottmc@sybase.com. What is XML Attributes and Elements Document Type Definition (DTD) Style Languages Supporting Technologies. Agenda. Extensible You can create your own tags Structured It add structure to your data
E N D
IAD 303XML Primer • Scott McReynolds • Product Line Specialist • IAD • scottmc@sybase.com
What is XML Attributes and Elements Document Type Definition (DTD) Style Languages Supporting Technologies Agenda
Extensible You can create your own tags Structured It add structure to your data XML does not provide meaning tags for the data, just a that it holds a particular structure. What is XML
Validation XML Can be validated Rules can be defined using Document Type Definition (DTD) DTD Helps provide a standard mechanism for specifying grammar XML sent that claims to be valid to a particular DTD can easily be checked. Guarantees data uniformity What is XML
The Basic Structured <HEADER1> <HEADER2> <HEADER3> </HEADER3> </HEADER2> </HEADER1> What does it look like
Example <CARTOONS> <SERIES> The Simpsons </ SERIES > <TITLE> Simpson Roasting on a Open Fire </TITLE> <SUMMARY> … </SUMMARY> </ CARTOONS > What does it look like
Design of Domain-Specific Markup Language Math, Chemistry, Math Self-Describing Data Not tied to a binary format Documenting of the data in the data itself Interchange of Data Among Applications OFX - Open Financial Exchange CDF - Microsoft Channel Definition Format J2EE - All Deployment Descriptors are XML based Why do we care?
Data can be manipulated with standard tools It is ASCII Can be viewed with standard tools Browser - IE, Netscape Editor - vi, Textpad, Notepad Different Views are easy to create using style sheets <?XML -stylesheet type=“text/css” href=“simpsonsheet.css”?> Why do we care?
Document Lifecycle HTML Web Browser Document Editor Business Process
What is XML Attributes and Elements Document Type Definition (DTD) Style Languages Supporting Technologies Agenda
Elements The Element that is defined. Has an Open and Close tag <Character Name=“Bart” Sex=“M”> </Character> Child Elements Meta-Data items of an Element <Character Name=“Bart” Sex= “M”> </Character> Elements
A value named pair associated with an element Each are strings No two attributes can contain the same name. <Character Name=“Bart” Sex=“M”> </Character> Attribute
Attributes can’t hold structure well Elements allow for meta-meta-data (information about the information about the information) <Character Name_1=“Bart” Sex_1=“M” Name_2=“Maggie” Sex_2=“F”> </Character> Not everyone agrees with what is meta-data Elements are more extensible in the fact of future changes. Attributes vs Elements
Empty Tags An element that has no content <Character></Character> or </Character> Comments Additional information you want included in a document <!-- comments begin here and end here --> Other Items
What is XML Attributes and Elements Document Type Definition (DTD) Style Languages Supporting Technologies Agenda
Using a Java Parser Sun MessageBroker What is DTD User Created Associated with am XML Document Embedded or External <!DOCTYPE doctype SYSTEM “simpson.dtd”> Validating XML Documents
Embedded DTD <!DOCTYPE cartoons> <!ELEMENT cartoon (series, title, summary)> <!ELEMENT series (#PCDATA)> <!ELEMENT title (#PCDATA)> <!ELEMENT summary (#PCDATA)> <!ATTLIST homerbeer (yes|no) “no”> ]> DTD Example
How do the fields break out Being and end tags <!DOCTYPE cartoons> ... ]> DTD Explanation
Declare the elements <!ELEMENT cartoon (series, title, summary)> This means our cartoon XML must have a series, title and summary DTD Explanation
Parsed Character Data Noted by the #PCDATA tag. Telling XML this field will just contain data. Attribute Validation Rules <!ATTLIST homerbeer (yes|no) “no”> Released can only have values of yes or no and the default is no DTD Example
Names Punctuation Symbols - _ : . Cannot begin with xml or XML Extended Backus-Naur Format () - Enclose a sequence of group of choices (series, title, summary) , - list of required elements that must appear in order (series, title, summary) | - Separate items in a list of choices (yes|no) Rules for specifying DTD
Names Extended Backus-Naur Format ? - Elements that can occur 0 or 1 times (series, title, summary?) * - Element can occur 0 or more times (series, title, summary?, specialguest*) + - Element can occur 1 or more times (series, title, summary?, charactersappearing*) Rules for specifying DTD
Data Types Tags can contain other tags. PCDATA - Parsed Character Data Parser will actually parse the text and look for specific constructs CDATA - Character Data Instructions stay as they are shown <!ATTLIST homerfood beer CDATA #REQUIRED> NMTOKEN/NMTOKENS Value must be a valid XML name(s) Rules for specifying DTD
Include/Ignore There are no looping tags Ignored - everything is ignored by the parser <[IGNORE [ bart (best line, trouble, homerproblem) ]]> Include - everything is included (not ignored) by the parser <[INCLUDE [ bart (best line, trouble, homerproblem, maggieinteraction) ]]> Rules for specifying DTD
Processing Instruction Instructions for the application using the XML document. <?xml version=“1.0”?> Give the processing instructions <?ApplicationName [instructions]?> Standalone option <?xml version=“1.0” standalone=“no”?> Character Set <?xml version=“1.0” standalone=“no” encoding=“UTF-8”?> Rules for specifying DTD
Rules can include them Remove Restriction Anything <!element episode ANY> Nothing <!element episode EMPTY> <element></element> <element/> Attribute Declaration
Predefined Attributes xml:space Describes how whitespace is treated <! ATTRLIST Description xml:space (default|perserve) ‘perserve’> xml:lang defines the language in which the elements content is written Attribute Declaration
Logical Components of your XML Element Names <!ATTLIST homerbeer (yes|no) “no”> All <!ATTLIST homer beertype CDATA> <homer beertype=“coors”>miller</<beertype> <homer beertype=“anykind”>bud</<beertype> <homer beertype=“yes”>Pete’s Wicked Ale</<beertype> Element Declaration
Element Names (continued) enumerated <!ATTLIST homerbeer (yes|no) “no”> required <!ATTLIST homerbeer (yes|no) “no” #REQUIRED> implied <!ATTLIST homerbeer (yes|no) “no” #IMPLIED> fixed value <!ATTLIST homerbeer (yes|no) “no” #FIXED “Pete’s Wicked Ale”> Element Declaration
Children examples Valid <!element episode (title | number)> <episode> <title> The episode title</title> </episode> or <episode> <number> 5</number> </episode> Element Declaration
Children examples Invalid <!element episode (title | number)> <episode> <title> The episode title</title> <number> 5</number> </episode> Both <!element episode (#PCDATA | number)> <episode> The episode title<number> 5</number> </episode> Element Declaration
Children examples Remove Restriction Anything <!element episode ANY> Nothing <!element episode EMPTY> <element></element> <element/> <element title=“episode title” number=4></element> Element Declaration
General Parameters Character Entity Declaration
General Make substitutions with an XML document Defined in DTD Substitution is intended for the body of the XML document <!Entity cartoonname=“The Tick”> in the XML <header>Information for &cartoonname</header> transforms into <header>Information for The Tick</header> Entity Declaration
Parameter Focuses on the DTD Reuse DTD more effectively Automatic Substitution <!Entity name “replacement text”> Entity Declaration
Parameter (Continued) Common Attributes <!Entity % commonAttributes “UserName CDATA #REQUIRED ModifiedDate CDATA #REQUIRED”> <!Element report (#PCDATA | content)*> <!ATTLIST report %commonAttributes; > Entity Declaration
Character Reserved/Special meaning XML < or “ & = & < = < > = > ' = ‘ "e; = “ Entity Declaration
Help application to process non-XML data. GIFs, Jpegs, etc. <!NOTATION gif SYSTEM “gifview.exe> Notation Declaration
What is XML Attributes and Elements Document Type Definition (DTD) Style Languages Supporting Technologies Agenda
Cascading Style Sheets Tend to work better for XML then HTML Proper support for nowrap Attaching Style Sheet to a document <?xml-stylesheet type=“text/css” href=“cartoon.css”> Selection of Elements selector is applied to an element CHARACTER { display: block; font-size: 16pt: font: bold} CSS
Grouping Selectors Apply the same properties to more then one element CHARACTER, SEX { display: block; font-size: 16pt: font: bold} Pseudo-Elements Apply a look to a part of a document CHARACTER:first-letter { display: block; font-size: 16pt: font: bold} CSS
Pseudo-Classes Style 2 elements of the same type differently Select the item by CLASS <CHARACTER CLASS=“Guest”>Mike Pizza</CHACTER> CSS Code CHARACTER.Guest { color:red } Select the item by ID <CHARACTER ID=“02”>Mike Pizza</CHACTER> CSS Code CHARACTER.#02 { color:red } CSS
Inheritance Allows for a sub-attribute to get the style information from it’s parent SERIES { font-weight: bold; font-size: 24pt} CHARACTER {font-size: 12} so <SERIES>Simpsons <CHARACTER>Homer </CHARACTER> </SERIES> CSS
STYLE Apply a Style to a particular Attribute <CHARACTER STYLE=“font-wieght: bold”>Homer</CHACTER> @import Allows a predefined directive that is stored in a separate file @import url(http://www.simpson.com/xml.css); For formatting information see a good XML book CSS
Extensible Style Language Includes both transformation and formatting Can work together or separately Can be part of DTD as well Trees Includes the root, Elements, Text, Attributes, Namespaces, Processing Instructions, Comments XSL
XSL Style Sheets Takes as input a tree which represents an XML document and produces as output a new tree as an XML document Contains a list of template rules XML is used to describe the rules, templates and patterns <xls:template match=“Comic Central”> <html> <xsl:apply-templates/> </html> <xls:template> XSL
Where does the transformation happen XML document and style sheet are both served to the client, the transformation occurs prior to being displayed Server applies the XSL style sheet to an XML document to transform it to another format (HTML) then sent to the client A program transforms the original XML document into another format before being sent to client or server. XSL
Each rule is a template Associate a particular output with and input Each xsl:template has a match It is the template to be instantiated May contain text that is to appear in the output document <xls:template match=“/”> <html> <head> </head> </html> <xls:template match=“/”> XSL Templates
xsl:apply-template Causes the formatting to be applied to the child nodes The select Attribute Used to select a particular set of children instead of all the children xsl:value-of copies the value of the node in the input document to the output document xsl:for-each Used in contexts where it is unambiguous as to which node’s value is being taken. First if multiple can be selected XSL Templates
Matching Patterns At root match = “/” At element level match = “elementName” With Children match = “element/child” With Descendants match = “parent//descendent” With ID match = “id(‘02’)” With @ match = “@elementName” With Comments match = “comment()” With OR operated match = “elementA|ElementB” With Test[] match = “element[child]” XSL Templates