Upload
cory-casey
View
227
Download
1
Tags:
Embed Size (px)
Citation preview
INFSY 547: WEB-Based Technologies
Gayle J Yaverbaum, PhD
Professor of Information Systems
Penn State Harrisburg
Document Type Definitions
XML Parsers
• Two types of parsers:– Validating: checks document against a DTD or
schema– Non-validating: recognizes syntax errors
• All parsers require well-formed documents
• Eclipse will check your document
DTD
• Describes the XML object to the processor • Models XML structure• Constrains the structure
– On sequence– On nesting of tags
• Content may be processed without a DTD
DTD’s:
1. Strict rule book for XML document
2. Each tag must be declared
3. Should not contain elements that are absent in the XML document
DTD• Schemas do the same and more
• Valid: Structure is correct
Ask Eclipse to check
• Well-formed: XML code may not be
be valid.
• DTD’s can be shared, guaranteeing consistency
DTD
• Provides a list of:– Elements– Attributes– Entities
• May be embedded in xml document file or in separate file– Always create an external DTD.
DTD
Attribute types:
PCDATA (parsed character data )• Only content
CDATA (character data that is not markup
DTD Document type declaration: refers to the external file:
<!DOCTYPE rootname SYSTEM “filename.dtd”>
Example: <!DOCTYPE PORTFOLIO SYSTEM “PortfolioProject.dtd”>
DTD keywords
ELEMENT Defines tags
ATTLIST Defines attributes
ENTITY Defines entities
DTD Element Declaration:
1. Element Type Declaration is main building block of a DTD
<!ELEMENT element name content specification>
2. May begin with a a) Letterb) Colonc) Underscore
3. Subsequent to the 1rst character, may also include a period and hyphen
1. Build the DTD hierarchically– i.e. from the outside/in2. Identify the root ELEMENT e.g. Example <!ELEMENT PORTFOLIO
(SECTION*,RESOURCES*,OTHER*)>
1) An * : 0..MANY 2) A + : 1..MANY 3) A ? : 1 TIME
DTD Element Declaration(describes document tree structure)
Element content/child element
Element Declarations:
1. Types of content within an ELEMENT
o A list of other elements (as per last page)
o Keyword EMPTY (if element will not
contain anything)
EMPTY e.g. <!ELEMENT ABC EMPTY>
o An element that has no content. i.e. no child elements.
<!ELEMENT group (app,author,title )>
o Referred to as having children specified.
Defining ELEMENT Content
1. Content specification
2. The right side (content specification/model) defines the left side (element name)
3. MIXED content specifies both PCDATA and other elements
4. <!ELEMENT distributorName (#PCDATA)>
Attribute declaration:
Can be located anywhere in the DTD
good practice: keep it close to the corresponding
element
Attributes cannot contain sub elements.
Attribute declaration
<!ATTLIST elementname attributename type default>
<!ATTLIST book lang CDATA
#REQUIRED >
Attribute that indicates a reference/link:
<!ELEMENT RESOURCES (address,title1)><!ATTLIST RESOURCES
type CDATA "href">
Note: xsl:
<xsl:template match="RESOURCES"> <xsl:for-each select=".">
<P><a> <xsl:attribute name="href">
<xsl:value-of select="address" />
</xsl:attribute> <xsl:value-of select="title1" />
</a></P></xsl:for-each>
Image!
DTD file:
PIC is listed in the appropriate ELEMENT list in the DTD
an attribute is then defined: ATTLIST elementname attributename CDATA #IMPLIED
Example of the attribute in the DTD file: <ATTLIST filename CDATA #IMPLIED>
Common Attributes types<!ATTLIST elementname attributename type
default>
1. #CDATA
• Stands for character/string data
• Contains any combination of characters except “<“ or “&”
• Is simple and easy to use
• May have multiple attributes for an element
2. #REQUIRED: attribute must contain some value
3. #IMPLIED: attribute has no default value and may be omitted
4. #FIXED fixedvalue: attribute must always be set to the value, fixedvalue
5. Default: merely type a default value instead of the above
Programmer Defined Entities
• An <!ENTITY> tag in the DTD
<!ENTITY univ “Penn State University”>• In the XML document:
Start with a “&” Ends with a “;” <school name=“&univ;”>• Once defined, you may use the entity
anywhere within your XML document.
Lab Assignment
To Be Added!