23
INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

Embed Size (px)

Citation preview

Page 1: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

INFSY 547: WEB-Based Technologies

Gayle J Yaverbaum, PhD

Professor of Information Systems

Penn State Harrisburg

Page 2: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

Document Type Definitions

Page 3: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

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

Page 4: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

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

Page 5: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

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

Page 6: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

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

Page 7: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

DTD

• Provides a list of:– Elements– Attributes– Entities

• May be embedded in xml document file or in separate file– Always create an external DTD.

Page 8: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

DTD

Attribute types:

PCDATA (parsed character data )• Only content

CDATA (character data that is not markup

Page 9: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

DTD Document type declaration: refers to the external file:

<!DOCTYPE rootname SYSTEM “filename.dtd”>

Example: <!DOCTYPE PORTFOLIO SYSTEM “PortfolioProject.dtd”>

Page 10: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

DTD keywords

ELEMENT Defines tags

ATTLIST Defines attributes

ENTITY Defines entities

Page 11: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

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

Page 12: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

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

Page 13: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

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)

Page 14: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

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.

Page 15: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

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)>

Page 16: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

Attribute declaration:

Can be located anywhere in the DTD

good practice: keep it close to the corresponding

element

Attributes cannot contain sub elements.

Page 17: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

Attribute declaration

<!ATTLIST elementname attributename type default>

<!ATTLIST book lang CDATA

#REQUIRED >

Page 18: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

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>

Page 19: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

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>

Page 20: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

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

Page 21: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

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

Page 22: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

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.

Page 23: INFSY 547: WEB-Based Technologies Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg

Lab Assignment

To Be Added!