1 / 57

IAD 303 XML Primer

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

emilia
Download Presentation

IAD 303 XML Primer

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. IAD 303XML Primer • Scott McReynolds • Product Line Specialist • IAD • scottmc@sybase.com

  2. What is XML Attributes and Elements Document Type Definition (DTD) Style Languages Supporting Technologies Agenda

  3. 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

  4. 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

  5. The Basic Structured <HEADER1> <HEADER2> <HEADER3> </HEADER3> </HEADER2> </HEADER1> What does it look like

  6. Example <CARTOONS> <SERIES> The Simpsons </ SERIES > <TITLE> Simpson Roasting on a Open Fire </TITLE> <SUMMARY> … </SUMMARY> </ CARTOONS > What does it look like

  7. 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?

  8. 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?

  9. Document Lifecycle HTML Web Browser Document Editor Business Process

  10. What is XML Attributes and Elements Document Type Definition (DTD) Style Languages Supporting Technologies Agenda

  11. 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

  12. 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

  13. 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

  14. 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

  15. What is XML Attributes and Elements Document Type Definition (DTD) Style Languages Supporting Technologies Agenda

  16. 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

  17. 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

  18. How do the fields break out Being and end tags <!DOCTYPE cartoons> ... ]> DTD Explanation

  19. Declare the elements <!ELEMENT cartoon (series, title, summary)> This means our cartoon XML must have a series, title and summary DTD Explanation

  20. 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

  21. 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

  22. 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

  23. 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

  24. 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

  25. 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

  26. Rules can include them Remove Restriction Anything <!element episode ANY> Nothing <!element episode EMPTY> <element></element> <element/> Attribute Declaration

  27. 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

  28. 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

  29. 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

  30. Children examples Valid <!element episode (title | number)> <episode> <title> The episode title</title> </episode> or <episode> <number> 5</number> </episode> Element Declaration

  31. 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

  32. Children examples Remove Restriction Anything <!element episode ANY> Nothing <!element episode EMPTY> <element></element> <element/> <element title=“episode title” number=4></element> Element Declaration

  33. General Parameters Character Entity Declaration

  34. 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

  35. Parameter Focuses on the DTD Reuse DTD more effectively Automatic Substitution <!Entity name “replacement text”> Entity Declaration

  36. Parameter (Continued) Common Attributes <!Entity % commonAttributes “UserName CDATA #REQUIRED ModifiedDate CDATA #REQUIRED”> <!Element report (#PCDATA | content)*> <!ATTLIST report %commonAttributes; > Entity Declaration

  37. Character Reserved/Special meaning XML < or “ &amp; = & &lt; = < &gt; = > &apos; = ‘ &quote; = “ Entity Declaration

  38. Help application to process non-XML data. GIFs, Jpegs, etc. <!NOTATION gif SYSTEM “gifview.exe> Notation Declaration

  39. What is XML Attributes and Elements Document Type Definition (DTD) Style Languages Supporting Technologies Agenda

  40. 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

  41. 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

  42. 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

  43. 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

  44. 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

  45. 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

  46. 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

  47. 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

  48. 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

  49. 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

  50. 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

More Related