CIS-189 Final Review


Published on

review materials for CIS-189

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

CIS-189 Final Review

  1. 1. Final Exam Review<br />CIS-189<br />
  2. 2. “Markup” refers to the use of tags to describe data<br />Data describing data is meta data<br />Tags identify where data begins and ends, and has some information about that data<br />Often referred to as “self describing”<br />Standard Generalized Markup Language was created to offer universal standards for sharing and moving information<br />Markup<br />
  3. 3. Extensible Markup Language fills the gap between display of HTML and complexity of SGML<br />XML is compatible with rules of SGML<br />XML isn’t a language<br />Set of standards about how to create a language to define and work with particular data<br />XML<br />
  4. 4. Tags are used similar to HTML<br />A tag must always have a close<br />&lt;name&gt;Randy&lt;/name&gt;<br />&lt;middle /&gt;<br />Tags are defined as needed<br />No set of predefined tags as in HTML<br />Tags typically aren’t about display<br />Display is separated from data, unlike HTML<br />Using XML<br />
  5. 5. XML is hierarchical<br />Individual items in XML are elements<br />One element can belong to another<br />Child and parent<br />Similar to a one-to-many relationship<br />Structure is called a ‘tree’ <br />An item with children is called a branch<br />An item with no children is a leaf<br />XML Structure<br />
  6. 6. An element can contain data<br />An element can contain other elements<br />An element can contain data and other elements<br />Definition of elements for specific data make up a vocabulary<br />Elements<br />
  7. 7. Complies with rules <br />Rules allow easy transfer and read of data independent of platform, application<br />Parser reads XML file<br />Parser typically runs as a service to another application<br />A file that doesn’t comply with rules has afatal errorand parser cannot continue<br />By definition, a file that isn’t well formed has a fatal error<br />Any violation of rules is an error<br />Well-Formed XML<br />
  8. 8. Start tag must have an end tag or be self-closing<br />Tags cannot overlap<br />Must have one – and only one – root element<br />Element names obey naming conventions<br />XML is case-sensitive<br />Whitespace is maintained in PCDATA<br />Well Formed<br />
  9. 9. Element name can include a space after the name<br />Element cannot have a space at beginning of start tag<br />Element name must begin with letters or dash<br />After the first character, numbers, hyphens, periods are acceptable<br />Cannot use spaces or: (colon) in names<br />Colon is reserved for special uses<br />XML cannot be used as the first 3 letters of a name (Upper, lower or mixed case)<br />Naming Elements<br />
  10. 10. CDATA refers to character data<br />Values that are treated as those characters<br />PCDATA refers to parsed character data<br />Values that are translated for a specific meaning or purpose<br />Whitespace is treated differently than HTML<br />Maintained<br />Carriage return and linefeed characters are both treated as single linefeed by parser<br />Working with Data<br />
  11. 11. Provide another way to represent values<br />Defined within the start tag of an element<br />Work in a name/value pair<br />Must include both a name and value for a valid statement (an empty string is a valid value)<br />Value must be enclosed in single or double quotes<br />Opening quote must be same as closing (can’t pair a single quote and double quote)<br />Be consistent for ease of coding, reading, and maintenance<br />Attributes<br />
  12. 12. Attribute names must conform to same rules as element names<br />Start with letter or dash<br />Can use numbers, hyphens, periods after the first character<br />Name of each attribute must be unique within an element<br />Attribute Names<br />
  13. 13. Elements can be more complex<br />Can include child elements if needed<br />Attributes are about a single value<br />Attributes can simplify logic<br />Can avoid or reduce nesting<br />Can simplify logic<br />Choice of element or attribute most often simply a design choice, preference<br />Using Attributes and Elements<br />
  14. 14. Provide information to aid the processing of the file<br />&lt;? XML version=“1.0”?&gt;<br />If include XML declaration must be first entry<br />Cannot have any character preceding the open tag<br />If include XML declaration must have at least the version<br />Have versions 1.0, 1.1<br />XML Declarations<br />
  15. 15. Optional settings are encoding, standalone<br />Encoding specifies which character set is being used (how characters are represented)<br />Standalone tells the parser if document is complete by itself, or relies on another file<br />Optional XML Declarations<br />
  16. 16. Processing instructions are for consuming application<br />Not used by XML parser<br />Includes information/commands that application needs to complete some task<br /> &lt;? Statement ?&gt;<br />Processing Instructions<br />
  17. 17. Some symbols have special meaning<br />Less than (&lt;)<br />Greater than (&gt;)<br />Ampersand (&)<br />Cannot use these characters directly unless wrapped in a CDATA section<br />If need single symbol can substitute<br />&lt for &lt;, &gt for &gt;, &amp for & <br />Special Characters<br />
  18. 18. DTD stands for Document Type Definition<br />Allows an XML document to go further than meeting the requirements of being well-formed<br />Specifies requirements to be valid<br />A valid XML document matches definitions of allowable elements, attributes<br />DTD Overview<br />
  19. 19. Validation can be done in code (i.e. using javascript, VB and DOM)<br />DTD’s allow use of a validating parser that compares the document against specifications<br />Typically makes application changes and maintenance easier<br />Less tied to a particular programming language/environment<br />Validation<br />
  20. 20. Includes name of root element<br />Allows specification of where the DTD is located<br />DTD can be embedded in the XML file (local)<br />DTD can refer to external file, Uniform Resource Identifier (URI)<br />Local takes precedence over external<br />Document Type Declaration<br />
  21. 21. Element Declaration has 3 parts:<br />Declaration<br />Element name<br />Element content<br />Element content can include a list of child elements or data<br />Element Declaration<br />
  22. 22. DTD included in XML document<br />Definition of a student:<br />&lt;!DOCTYPE student[<br />&lt;!ELEMENT student(first, last, studentID)&gt;<br />&lt;!ELEMENT first (#PCDATA)&gt;<br />&lt;!ELEMENT last(#PCDATA)&gt;<br />&lt;ELEMENT studentID(#PCDATA)&gt;<br />]&gt;<br />LocalDTD<br />Document Type Declaration<br />Element Declaration<br />A student element is made up of first name, last name, and student id elements<br />
  23. 23. DTD exists in external file/location<br />Must use keyword to specify type of location<br />SYSTEM is a reference to local file system<br />PUBLIC is reference to DTD accessed through a catalog<br />Can use both together<br />If can’t find catalog reference can use specified file<br />External Definition<br />
  24. 24. Reference in XML file:<br />&lt;!DOCTYPE student SYSTEM “student.dtd”&gt;<br />External file:<br />&lt;!ELEMENT student(first, last, studentID)&gt;<br />&lt;!ELEMENT first (#PCDATA)&gt;<br />&lt;!ELEMENT last(#PCDATA)&gt;<br />&lt;ELEMENT studentID(#PCDATA)&gt;<br />]&gt;<br />Sample External Definition<br />Document Type Declaration<br />Element Declaration<br />
  25. 25. Element name must match name in XML document<br />If using namespaces, prefixes must match<br />Content Model defines what the element can store<br />An element<br />Mixed (i.e. data and element)<br />Empty<br />Any<br />Working With Elements<br />
  26. 26. Error raised if an element is missing<br />Error raised if there are extra elements<br />Error raised if elements in a different order<br />For a student, our content must be in firstname, lastname, studentID order<br />If find an element “major”, error<br />If order varies, error<br />If missing first, last, or studentID, error<br />Content by Sequence<br />
  27. 27. Can allow content to vary between elements<br />| (vertical bar or pipe) indicates OR<br />If add a Grade element to a student that can be a letter or percent:<br />&lt;!ELEMENT grade (letter | percent)&gt;<br />&lt;!ELEMENT letter (#PCDATA)&gt;<br />&lt;!ELEMENT percent (#PCDATA)<br />Indicates that must have letter or percent element<br /> Content by Choice<br />
  28. 28. Allows combination of elements and parsed character data<br />Can include additional information within an element, eg. how to display<br />Rules:<br />Managed by using Choice (or)<br />PCDATA must appear first in list of elements<br />List cannot include inner content model (only simple elements)<br />If there are child elements, include * <br />* Indicates that may appear zero or more times<br />Mixed Content<br />
  29. 29. If want to include emphasis with the letter grade<br />Data: &lt;letter&gt;&lt;em&gt;4&lt;/em&gt;&lt;/letter&gt;<br />Declaration:<br />&lt;!ELEMENT letter (#PCDATA | em)*&gt;<br />Describes a letter element as the content (pcdata) plus emphasis element<br />Mixed Content -2 <br />
  30. 30. An element can be empty<br />&lt;br /&gt; (never has child, content)<br />Declaration includes EMPTY:<br />&lt;!ELEMENT br EMPTY&gt;<br />Means that the element CANNOT contain content<br />Empty Content<br />
  31. 31. An element can contain any kind of value (or be empty)<br />Any elements declared in the DTD can occur, any number of times<br />Only elements that are part of the DTD can be part of the document!<br />May be empty<br />May contain PCDATA<br />Least restrictive model<br />Any Content<br />
  32. 32. How many times can an element occur?<br />How many times must an element occur?<br />Cardinality<br />
  33. 33. Elements tend to be used to describe a logical unit of information<br />Attributes are typically used to store data about characteristics (properties)<br />May have a Movie element with attributes for Title, Rental Price, Rental Days<br />No specific rules about how to use elements and attributes<br />Attributes and DTD’s<br />
  34. 34. Attributes allow more limits on data<br />Can have a list of acceptable values<br />Can have a default value<br />Some ability to specify a data type<br />Concise, about a single name/value pair<br />Attributes have limits<br />Can’t store long strings of text<br />Can’t nest values<br />Whitespace can’t be ignored<br />Attributes and Elements<br />
  35. 35. Declaration:<br />&lt;!ATTLISTElementNameAttrNameAttrType Default&gt;<br />Specify the Element the attribute belongs to<br />Specify the Name of the attribute<br />Specify the Type of data the attribute stores<br />Specify characteristics of the values (Default or attribute value)<br />List either the default value or other characteristic of value – required, optional<br />Specifying Attributes<br />
  36. 36. CDATA – unparsed character data<br />Enumerated – series/list of string values<br />Entity/Entities – reference entity definition(s)<br />ID – unique identifier for the element<br />IDREF – refer to the ID of another element<br />IDREFS – list of ID’s of other elements separated by whitespace<br />NMTOKEN/NMTOKENS – value(s) of attribute can be anything that follows rules for XML name<br />Sample Attribute Data Types<br />
  37. 37. Specifies that attribute value must be found in a particular list<br />Each value in list must be valid XML name<br />Limits on spaces, characters<br />Use | (pipe) to separate members of list<br />If specifying list letter grades for a student:<br />&lt;!ATTLIST student grade (A | B | C | D | F | V | W | I) #IMPLIED&gt;<br />Enumerated Attributes<br />Element<br />Attribute<br />Enumerated List<br />
  38. 38. An ID specifies that the element must have a unique value within the document<br />Allows reliable way to refer to a specific element<br />No spaces allowed in value<br />Typically replace space with underscore<br />Attribute list can include only one ID<br />IDREF, IDREFS allows an element to be associated with another or multiple other elements<br />A student element must have a student ID:<br />&lt;!ATTLIST student studentID ID #REQUIRED&gt;<br />ID, IDREF, IDREFS<br />
  39. 39. Attributes can refer to entities<br />“Entity” refers to substituting a reference for a text value<br />&amp; refers to the & character<br />Unparsed Entity is a reference that isn’t parsed<br />Can reuse references for long values, or hard to manage characters (i.e. tab, line feed)<br />Entity must be declared in the DTD<br />&lt;!ENTITY classTitle “XML”&gt;<br />When classTitle found in document, replaced with XML<br />Entities and Attributes<br />
  40. 40. Can specify how the value will appear in the document<br />Must always specify a value declaration<br />DEFAULT sets a value for an attribute if a value isn’t provided<br />Include default value in double quotes<br />FIXED sets a value that must occur; if an attribute has a different value, a validation error occurs<br />REQUIRED specifies that the attribute (and value) must exist<br />IMPLIED means the attribute is optional<br />Attribute Value Declarations<br />
  41. 41. Alternative to DTD’s as way to define structure<br />Essentially defining a language<br />Structure may be also referred to as vocabulary<br />Ensures that data matches specifications<br />Serves as basis for other XML-related technologies<br />XML Schemas<br />
  42. 42. Use XML for definition<br />Doesn’t have separate structure like DTD’s<br />Schema must be well-formed<br />Support Namespace recommendations<br />Allows same name to be used in different Schemas and properly understood<br />Provides for built-in and user-defined data types<br />Can be easily reused<br />Supports concepts such as inheritance<br />One object is based on another<br />Working with Schemas<br />
  43. 43. Allows more specificity than DTD’s<br />Can specify dates, numbers, ranges<br />Datatypes fall into two categories:<br />Simple deals with basic values<br />Complex describes more intricate values or structures<br />Schema Datatypes<br />
  44. 44. Schema file uses an .xsd extension<br />Root element is the schema<br />Can nest all elements within the schema<br />Everything is hierarchical<br />OR<br />Can have multiple elements as child elements of the schema root<br />Allows use of a definition any place in the document (data) file<br />Elements which are child elements of schema are global<br />Creating Schemas<br />
  45. 45. Simple data type is about text, numbers, date<br />Sometime referred to as “primitives”<br />Data types built in to Schema vocabulary (and related elements, attributes) are in the XML Schema namespace<br />Need reference to namespace to have valid XML – where to find the definition<br />Elements that are Simple Datatypes don’t have attributes<br />Including an attribute makes an element Complex<br />Simple Datatypes<br />
  46. 46. The simpleType allows customization of base types<br />Can create limits on values<br />Specify ranges<br />Specify lists<br />&lt;xsd:simpleType=“Degrees”&gt;<br /> &lt;xsd:restriction base=“xsd:string”&gt;<br /> &lt;xsd:enumeration value=“AA” /&gt;<br /> &lt;xsd:enumeration value=“AS” /&gt;<br /> &lt;/xsd: restriction&gt;<br />&lt;/xsd:simpleType&gt;<br />Defining (Simple) Datatypes<br />
  47. 47. Allows combination of different elements and specification of order, new data types<br />Can create an element Course which is comprised of simple types<br />&lt;xsd:element name=“course”&gt;<br /> &lt;xsd:complexType&gt;<br /> &lt;xsd:sequence&gt;<br /> &lt;xsd:element name=“department” type=“xsd:string”/&gt;<br /> &lt;xsd:element name=“number” type=“xsd:string”/&gt;<br /> &lt;xsd:element name=“title” type=“xsd:string”/&gt;<br /> &lt;xsd:element name=“credits” type=“xsd:integer”/&gt;<br /> &lt;/xsd:sequence&gt;<br /> &lt;/xsd:complexType&gt;<br />&lt;/xsd:element&gt;<br />ComplexDatatypes<br />
  48. 48. When using a schema, need to create a reference from data file<br />Use either the schemaLocation or noNamespaceSchemaLocation attribute of the root element<br />&lt;course xmlns:xsi= xsi:noNamespaceShemaLocation=“course.xsd”&gt;<br />Using a Schema<br />
  49. 49. Qualification refers to whether a value (element, attribute) must be qualified by a its namespace<br />When an element (or attribute) doesn’t have a namespace declaration it’s unqualified<br />Determines how name is used in data (instance) document<br />A schema has the attributes elementFormDefault and elementFormDefault<br />Set to qualified or unqualified<br />By setting to qualified, must include a namespace when use attributes or elements<br />Qualification<br />
  50. 50. Allows elements to appear in any order or not at all<br />Rules governing use<br />Must be only content model declaration of a &lt;complexType&gt; definition <br />For example, can’t follow with &lt;sequence&gt;<br />Can only have element declarations as children<br />The children of the &lt;all&gt; element may appear once – or not at all<br />&lt;all&gt; Declaration<br />
  51. 51. Can create a group of attributes similar to element groups<br />Allows re-use of common members without multiple definitions<br />Attribute groups cannot be recursive (refer to themselves<br />Attribute Groups<br />
  52. 52. A list allows an element or attribute to store multiple values<br />Values are separated by whitespace, so whitespace cannot be part of the content<br />itemType attribute defines the data type<br />Can be built-in XML or a defined simpleType data type<br />&lt;list&gt; Declarations<br />
  53. 53. &lt;union&gt; allows the combination of two data type for an element or attribute<br />If have a possiblePoints element, expected value would be an integer; &lt;union&gt; would allow a string entry to note a “Missing” value<br />Separate data types with whitespace<br />&lt;simpleType name=“CreditValue”&gt;<br />&lt;union memberTypes=“xs:integerxs:string /&gt;<br />&lt;/simpleType<br />&lt;union&gt; Declarations<br />
  54. 54. XSL stands for Extensible Stylesheet<br />Stylesheets are used to manage organization and presentation of data<br />Implemented as an XML language<br />Rules of XML apply<br />Made up of<br />XSL-FO (Formatting Objects)<br />XSLT (Transformations)<br />XSL<br />
  55. 55. XSL-FO focused on presentation to screen and paper<br />Not well-supported by browsers<br />XSLT emphasizes re-organization of data<br />Typically used for presentation but can also be used for conversion of data storage format<br />XSLT is a declarative language <br />Similar to SQL, describe results not steps<br />XSL Implementation<br />
  56. 56. Cascading Style Sheets used to separate presentation from data<br />XSLT used to change – transform – data<br />Convert an XML document to XHTML<br />Can use both together<br />XSLT v CSS<br />
  57. 57. XSL requires several steps<br />XML processor reads document<br />Creates document tree<br />XSL processor applies rules from stylesheet<br />Rules applied to document tree<br />Rules applied by using pattern matching<br />Identify nodes to apply rules to<br />Rules are stored as templates<br />Using XSL<br />
  58. 58. XSL works by using an Input Tree<br />Input Tree comes from XML processor<br />Process of changing input values is call Tree Transformation<br />Result of transformation is the Result Tree<br />Result Tree can include<br />XML<br />HTML (must adhere to XML rules, i.e., XHTML)<br />Formatting Objects<br />XSL Process<br />
  59. 59. Extensible Stylesheet Transformations is method of changing (transforming) XML based on rules of a stylesheet<br />Xpath allows manipulation of parts of XML document<br />Not XML-based<br />Provides compact references<br />Useful in URI’s, attributes<br />Document must exist as nodes (previously parsed)<br />XSLT<br />
  60. 60. Templates are definitions of rules, organization<br />Patterns define values searching for (where to apply templates)<br />Expressions allow use of functions using nodes as inputs<br />When referring to document attributes preface name with “@”<br />XSLT Constructs<br />
  61. 61. &lt;xsl:stylesheet&gt; is root element<br />Uses namespace to define elements, attributes valid in a stylesheet<br />&lt;xsl:template&gt; defines the rules/ transformations to apply<br />Match attribute specifies pattern to apply rules to<br />Functions similar to criteria<br />&lt;xsl:apply-templates&gt; applies the rules defined for a particular element<br />Select attribute specifies elements to apply to<br />XSLT Elements<br />
  62. 62. &lt;xsl:value-of&gt; returns the value of a specified node, function<br />Select attribute specifies value source<br />&lt;xsl:copy&gt; copies a node to the result tree without any child nodes or attributes<br />&lt;xsl:copy-of&gt; copies a node and child/attribute nodes<br />&lt;xsl:output&gt; controls the result tree<br />method=“xml|html|text”<br />XSLT Elements – 2<br />
  63. 63. &lt;xsl:if&gt; provides a boolean test to determine processing<br />&lt;xsl:choose&gt; offers an IF ... THEN ... ELSE construct<br />&lt;xsl:for-each&gt; allows each node in a group to be processed<br />&lt;xsl:sort&gt; specifies order for a group of nodes<br />XSLT Elements – 3<br />
  64. 64. Match can use <br />node name<br />current position (represented by “.”)<br />relative position (for example, parent = “..”)<br />Specifies where the transformation to be applied<br />Match<br />
  65. 65. XPath provides a logical model for working with XML document<br />Nodes are used to represent serialized XML (in memory)<br />Not all parts of XML document are represented (XML declaration, DOCTYPE)<br />XPath used in combination with other tools (such as XSLT)<br />XPATH Introduction<br />
  66. 66. Legal XPath code is called an expression<br />XPath expressions that return a node set is a location path<br />Expressions can be absolute and relative<br />Absolute path includes a full definition of how to find node<br />Relative path is based on current context (location)<br />XPath Expressions<br />
  67. 67. Root node represents document<br />Can have only one child node (document element)<br />Element node represents elements<br />QName (qualified name) includes namespace prefix and element name<br />Attribute node represent attributes<br />Have name and value<br />Are not represented as child nodes<br />Text node represents text value of an element<br />Does not have a name<br />Namespace node gives access to the namespace URI and prefix<br />Comment node<br />Processing Instruction Node<br />Node Types<br />
  68. 68. Boolean<br />Written as true() and false()<br />String<br />Number – floating point values<br />Node-set – unordered set<br />Follows document order<br />XPath 1.0 Types<br />
  69. 69. Element node references can be spelled out or abbreviated<br />/child::movies/child::movie/child::price<br />OR<br />/movies/movie/price<br />child::nodename can also be written nodename<br />Attribute node references<br />attribute::attributename<br />OR<br />@attributename<br />XPath Abbreviations<br />
  70. 70. self<br />child<br />attribute<br />ancestor<br />ancestor-or-self<br />descendant<br />descendent-or-self<br />following<br />following-sibling<br />namespace<br />parent<br />preceding<br />preceding-sibling<br />13 Axes<br />
  71. 71. Default axis<br />Selects nodes that are immediate nodes of context (current) node<br />Can use * to refer to all child nodes<br />Child Axis<br />
  72. 72. Can use node() to return all child nodes including comments, processing instructions, and text nodes<br />Can return just text nodes using text()<br />Text nodes are unnamed<br />Child Axis References<br />
  73. 73. Used to select attributes belonging to a particular element node<br />To return all attributes<br />attribute::*<br />@*<br />To return particular attribute<br />attribute::attributename<br />@attributename<br />Attribute Axis<br />
  74. 74. Used to filter node sets<br />Predicate similar to query criteria<br />Can use specific values or location references<br />Predicates<br />