XML - PowerPoint PPT Presentation

1 / 78
About This Presentation
Title:

XML

Description:

Almost any name can be used to create a namespace prefix. ... IDREF attributes point to elements with ID attribute. ... same value for multiple ID attributes is ... – PowerPoint PPT presentation

Number of Views:95
Avg rating:3.0/5.0
Slides: 79
Provided by: higg2
Category:
Tags: xml | attribute

less

Transcript and Presenter's Notes

Title: XML


1
XML
  • An introduction and DTD coverage

2
xml
  • XML like HTML is created from the Standard
    Generalized Markup Language, SGML

3
A brief introduction to XML A simple xml doc
  • lt?xml version 1.0?gt
  • lt! a simple xml examplethis is a comment --!gt
  • ltmymessagegt
  • ltmessagegtWelcome to XML!lt/messagegt
  • lt/mymessagegt

4
In validator file is in examples\ch05\intro.xml
5
XML documents and format
  • An XML document contains data, not formatting
    information. As well learn, there are ways (xsl
    and fo files, for example) to provide formatting
    for xml analogous to that in which css provided
    formatting for html.

6
XML
  • XML are typically stored in a file with suffix
    .xml, though this is not required. They can be
    created with any editor (save as ASCII text).
    Many packages like MS Word can save files as type
    .xml
  • An xml document contains a single root which
    contains other elements, Anything appearing
    before the root is called the prolog. Elements
    directly under the root are its children. The
    structure is recursive.
  • In the example, the roots child message contains
    the text Here is some message.

7
The character set
  • XML characters are CR, LF and Unicode.
  • An XML document consists of markup and character
    data.
  • Markup is enclosed in angle brackets (like html)
    ltgt
  • Character data appears between the start and end
    tag.
  • An xml parser passes whitespace characters to the
    application. Insignificant whitespace can be
    collapsed in a process called normalization.
  • It is a good idea to add whitespace to an xml
    document for readability.
  • , lt, gt, and are reserved characters. An
    entity reference makes it possible to use these
    as characters in the character data part of an
    xml document.
  • Entity references begin with and end with
  • In this way character data is not confused with
    markup.
  • Single and double quote are used to delimit
    attribute values.

8
More on syntax
  • There must be exactly one root.
  • Proper nesting of elements is required.
  • Start tags require close tags.
  • Unlike HTML, the author can define her own tags
    in XML.
  • Tags are case sensitive
  • Parser needs to distinguish markup from character
    data
  • Typically whitespace is normalized reduced to 1
    whitespace char.
  • Entity references are marked with an ampersand
    and allow us to use meta characters (lt, gt and
    so on) which are part of the language syntax.
  • Entity references (for example, lt) allow us to
    represent and distinguish the reserved characters
    lt,gt, in XML.
  • They may only appear as an entity reference in
    character data

9
XML intro continued
  • A DOM-based parser returns a tree structure. A
    DOM parser must process the entire document to
    create a (java) object which may be 3 or 4X the
    size of the original. Not advisable if there are
    storage size constraints.
  • A SAX (Simple-API for XML) -based parser returns
    events. SAX parsers have a smaller footprint.
  • Many parsers can be downloaded for free and
    several come with java 1.4

10
A brief introduction to XML
  • An xml validator parses an XML document and
    indicates if it is correct.
  • A number of free Validators are available,
    including one form MS which I downloaded and used.

11
Validator
  • Microsoft provides a validating program free for
    download (with javascript and VBscript versions)
    at
  • http//msdn.microsoft.com/archive/default.asp?url
    /archive/en-us/samples/internet/xml/xml_validator/
    default.asp
  • Or search MSDNvalidator

12
Validator links in my internet programming
directory
  • http//employees.oneonta.edu/higgindm/internet20p
    rogramming/validate_js.htm
  • This is a link for javascript validator
  • http//employees.oneonta.edu/higgindm/internet20p
    rogramming/validate_vbs.htm
  • This is a link for vbscript validator

13
MS Validatorhttp//employees.oneonta.edu/higgind
m/internet20programming/validate_js.htm
14
Parser continued
  • The parser will indicate if the document is
    well-formed.
  • In DOM-based parsing, a in the left margin
    indicates a node has children and a indicates
    all child nodes have been expanded.
  • The MS Validator uses color coding to indicate
    child nodes can be expanded
  • An element that stores other elements is called a
    container element.
  • The parser makes the document content available
    for further processing if it is well-formed.

15
Validator example
16
Validator
17
Reserved characters
  • ltmessagegtltgtamplt/messagegt would enable a
    character data message to contain characters ltgt

18
DTD document type definition
  • a dtd file may contain the definition of an xml
    structure.
  • XML files may refer back to a dtd.
  • If an XML document that has a DTD or Schema a
    validating parser can determine if it is not
    merely well-formed XML, but valid.
  • Valid means conforming to a dtd or schema.

19
Another example Unicode
  • Lang.xml (next slide) uses unicode entity
    references to represent arabic words.
  • lang.dtd (also shown in a later slide) is used to
    generate unicode characters (arabic) for some
    entity references in the XML file.

20
DTD document type definition a dtd file may
contain the definition of an xml structure.
  • lt?xml version "1.0"?gt
  • lt!-- Fig. 5.4 lang.xml --gt
  • lt!-- Demonstrating Unicode --gt
  • lt!DOCTYPE welcome SYSTEM "lang.dtd"gt
  • ltwelcomegt
  • ltfromgt
  • lt!-- Deitel and Associates --gt
  • 158315751610157816141604
  • 157116061583
  • lt!-- entity --gt
  • assoc
  • lt/fromgt
  • ltsubjectgt
  • lt!-- Welcome to the world of Unicode --gt
  • 15711607160415751611
  • 157616031605
  • 160116101616
  • 1593157516041605
  • lt!-- entity --gt

21
Lang.dtd
  • lt!-- lang.dtd --gt
  • lt!ELEMENT welcome ( from, subject )gt
  • lt!ELEMENT from ( PCDATA )gt
  • lt!ELEMENT subject ( PCDATA )gt
  • lt!ENTITY assoc "15711587161716081588
    161616101614157816181587"gt
  • lt!ENTITY text "15751604161016081606
    1610160316081583"gt

22
Lang.xml in validator
23
Lang.xml in IE
24
About the example
  • The DTD reference contains DOCTYPE, the name of
    the root, the SYSTEM flag indicating the DTD file
    is external, and the name of that file.
  • Root element welcome contains two elements from
    and subject.
  • Some lines contain entity references for unicode.
  • The DTD also defines some other entity references.

25
More about markup
  • XML end tags may consist of /gt if there is an
    empty element as in
  • ltemptyelt xxxx /gt
  • but otherwise must consist of a complete end-tag
    as in
  • ltsometaggt xxxxxxxxxxx lt/sometaggt
  • Elements may or may not have content (child
    elements or character data)
  • Elements may have 0 or more attributes associated
    with them. Attributes appear in the elements
    start tag
  • ltcar doors 4/gt
  • Attribute values must appear in single or double
    quotes.
  • Element and attribute names may not contain
    blanks.
  • Here, element car has attribute doors with value
    4.
  • Attributes may contain any characters and be of
    any length but must start with a letter or
    underscore.

26
Usage.xml uses a stylesheet
  • lt?xml version "1.0"?gt
  • lt!-- Fig. 5.5 usage.xml --gt
  • lt!-- Usage of elements and attributes --gt
  • lt?xmlstylesheet type "text/xsl" href
    "usage.xsl"?gt
  • ltbook isbn "999-99999-9-X"gt
  • lttitlegtDeitelaposs XML Primerlt/titlegt
  • ltauthorgt
  • ltfirstNamegtPaullt/firstNamegt
  • ltlastNamegtDeitellt/lastNamegt
  • lt/authorgt
  • ltchaptersgt
  • ltpreface num "1" pages
    "2"gtWelcomelt/prefacegt
  • ltchapter num "1" pages "4"gtEasy
    XMLlt/chaptergt
  • ltchapter num "2" pages "2"gtXML
    Elements?lt/chaptergt

27
Usage.xls
  • In notes
  • lt? Xxxxx ?gt in usage.xml represents a pi (that
    is, a processing instruction). PI consist of a
    PI target (xmlstylesheet, in this example) and a
    PI value. Note syntax.
  • PI can be used to help authors embed
    application-specific data in an xml document. If
    the application processing the xml doesnt use
    the PI, then it has no effect on the xml document
    content.

28
Usage.xml in validator
29
Usage.XML document loaded into IE Browser uses
stylesheet to generate HTML
30
CData
  • CData sections of an XML text, reserved chars or
    whitespace. The character data appearing in
    CData sections is ignored by the xml parser.
  • CData might be used for JavaScript or VBScript.
  • CData starts with lt!CData and ends with gt
  • CData may contain reserved characters, but not
    the text gt

31
Text example 5.7
  • lt?xml version "1.0"?gt
  • lt!-- Fig. 5.7 cdata.xml --gt
  • lt!-- CDATA section containing C code --gt
  • ltbook title "C How to Program" edition "3"gt
  • ltsamplegt
  • // C comment
  • if ( this-gtgetX() lt 5 ampamp
    value 0 ! 3 )
  • cerr ltlt this-gtdisplayError()
  • lt/samplegt
  • ltsamplegt
  • lt!CDATA
  • // C comment
  • if ( this-gtgetX() lt 5 value 0 ! 3
    )
  • cerr ltlt this-gtdisplayError()
  • gt
  • lt/samplegt
  • C How to Program by Deitel amp Deitel
  • lt/bookgt

32
CData example from text 5.7
33
Cdata.xml in MS validator (file is in
examples\ch05)
34
letter.xml - I removed blank lines to get it to
fit
  • lt?xml version "1.0"?gt
  • ltlettergt
  • ltcontact type "from"gt
  • ltnamegtJane Doelt/namegt
  • ltaddress1gtBox 12345lt/address1gt
  • ltaddress2gt15 Any Ave.lt/address2gt
  • ltcitygtOthertownlt/citygt
  • ltstategtOtherstatelt/stategt
  • ltzipgt67890lt/zipgt
  • ltphonegt555-4321lt/phonegt
  • ltflag gender "F"/gt
  • lt/contactgt
  • ltcontact type "to"gt
  • ltnamegtJohn Doelt/namegt
  • ltaddress1gt123 Main St.lt/address1gt
  • ltaddress2gtlt/address2gt
  • ltcitygtAnytownlt/citygt
  • ltstategtAnystatelt/stategt
  • ltzipgt12345lt/zipgt

35
letter.xml in Validator
36
namespaces
  • Naming collisions can occur when xml authors use
    the same tag names
  • Namespaces provide a mechanism for making tag
    references unambiguous.
  • A namespace reference appears with the start and
    end tags followed by a colon. So,
  • ltmoviecharactergtScroogelt/moviecharactergt can be
    differentiated from ltasciicharactergtcolonlt/ascii
    charactergt
  • Namespace prefixes are tied to unique URI in the
    xml document. Almost any name can be used to
    create a namespace prefix.
  • In this example ascii and movie are namespace
    prefixes. Namespace prefixes can precede element
    and attribute values to avoid collisions.
  • A URL may be used for a URI. The only
    requirement though is uniqueness as the URLs are
    not visited by the parser.

37
Namespace example 5.8
  • lt?xml version "1.0"?gt
  • lt!-- Fig. 5.8 namespace.xml --gt
  • lt!-- Namespaces --gt
  • lttextdirectory xmlnstext "urndeiteltextInfo"
  • xmlnsimage "urndeitelimageInfo"gt
  • lttextfile filename "book.xml"gt
  • lttextdescriptiongtA book listlt/textdescript
    iongt
  • lt/textfilegt
  • ltimagefile filename "funny.jpg"gt
  • ltimagedescriptiongtA funny
    picturelt/imagedescriptiongt
  • ltimagesize width "200" height "100"/gt
  • lt/imagefilegt
  • lt/textdirectorygt

38
Namespace.xml in validator file is in
examples\ch05
39
Namespace.xml example 5.8 in IE
40
Namespaces continued
  • Providing a prefix can be tedious. A default
    namespace can be created and elements and
    attributes used in the xml document from this
    namespace do not need prefixes.

41
Default namespaces
  • lt?xml version "1.0"?gt
  • lt!-- Fig. 5.9 defaultnamespace.xml --gt
  • lt!-- Using Default Namespaces --gt
  • ltdirectory xmlns "urndeiteltextInfo"
  • xmlnsimage "urndeitelimageInfo"gt
  • ltfile filename "book.xml"gt
  • ltdescriptiongtA book listlt/descriptiongt
  • lt/filegt
  • ltimagefile filename "funny.jpg"gt
  • ltimagedescriptiongtA funny
    picturelt/imagedescriptiongt
  • ltimagesize width "200" height "100"/gt
  • lt/imagefilegt
  • lt/directorygt

42
Default namespaces
  • Now, file is in the default namespace.
  • Compare this example to the earlier namespace
    example where text and image were distinct
    namespaces.

43
Defaultnamespace.xml in IE
44
DTD document type definition
  • A DTD is defined using EBNF (extended BNF) and
    can be used to specify allowable elements and
    attributes for an XML document.
  • There is a move away from DTD currently, toward
    Schema. Schema documents have XML (not BNF)
    syntax.
  • Some parsers can check an XML document against
    its DTD and determine if it is valid. These are
    called validating parsers. A document which is
    syntactically correct but does not correspond to
    its DTD is well-formed. Non-validating parsers
    cant check documents against their DTD and can
    thus only determine if the document is
    well-formed.

45
Document Type Declaration
  • ltDOCTYPE.gt in an XML document prolog is used to
    specify DTD appearing within or outside the
    document. These are referred to as the internal
    or external subset.
  • ltDOCTYPE thingy
  • lt!ELEMENT thingy (PCDATA)gt
  • gt
  • Declares a dtd called thingy with one element in
    the internal subset.
  • PCDATA refers to parseable character data
    meaning reserved characters lt,gt and within the
    PCDATA will be treated as markup. The
    parentheses contain the content specification for
    the element.

46
MS XML validator
  • We can check an xml document for adherence to an
    external DTD using MS XML validator. Heres the
    xml
  • lt?xml version "1.0"?gt
  • lt!-- Fig. 6.1 intro.xml --gt
  • lt!-- Using an external subset --gt
  • lt!DOCTYPE myMessage SYSTEM "intro.dtd"gt
  • ltmyMessagegt
  • ltmessagegtWelcome to XML!lt/messagegt
  • lt/myMessagegt
  • And heres the DTD
  • lt!-- Fig. 6.2 intro.dtd --gt
  • lt!-- External declarations --gt
  • lt!ELEMENT myMessage ( message )gt
  • lt!ELEMENT message ( PCDATA )gt

47
MS Validating parser can validate against schema
or dtd
48
Invalid xml
  • In the next slide we use the MS XML validator to
    check an xml (appearing below) like intro.xml but
    missing the message element
  • lt?xml version "1.0"?gt
  • lt!-- Fig. 6.3 intro-invalid.xml --gt
  • lt!-- Simple introduction to XML markup --gt
  • lt!DOCTYPE myMessage SYSTEM "intro.dtd"gt
  • lt!-- Root element missing child element message
    --gt
  • ltmyMessagegt
  • lt/myMessagegt

49
If xml doc does not match dtd/schema
50
Sequences, pipes and occurrences
  • The comma can be used to indicate a sequence in
    which elements must appear.
  • lt!ELEMENT class (prof, student)gt
  • Indicates the order and number of elements making
    up a class one prof and one student, in that
    order. Content may specify any number of
    elements.
  • lt!ELEMENT sidedish (coleslawchips)gt
  • Indicates just one of the choices must be
    selected.
  • , , and ? Indicate frequency of element
    occurrences.
  • means 1 or more occurences, means 0 or more
    occurences, ? Means 0 or 1 occurrence.
  • lt!ELEMENT class (prof, student)gt
  • Might be appropriate for a class DTD meaning just
    one professor and one or more students.

51
example
  • lt!ELEMENT donuts (jelly?,lemon,((crèmesugar)gl
    azed))gt
  • Specifies donuts consists of 0 or 1 jelly, 0 or
    more lemon, 1 or more of crème or sugar, or a
    glazed. A legal markup for this would be
  • ltdonutsgt
  • ltjellygtgrapelt/jellygt
  • ltlemongtsourlt/lemongt
  • ltlemongtreal sourlt/lemongt
  • ltglazedgtchocolatelt/glazedgt
  • lt/donutsgt

52
The dtd and xml
  • Pastry.dtd
  • lt!ELEMENT jelly (PCDATA)gt
  • lt!ELEMENT glazed (PCDATA)gt
  • lt!ELEMENT lemon (PCDATA)gt
  • lt!ELEMENT creme (PCDATA)gt
  • lt!ELEMENT sugar (PCDATA)gt
  • lt!ELEMENT donuts (jelly?,lemon,((cremesugar)gl
    azed))gt
  • Pastry.xml
  • lt?xml version "1.0"?gt
  • lt!-- pastry.xml --gt
  • lt!-- Using an external subset --gt
  • lt!DOCTYPE donuts SYSTEM "pastry.dtd"gt
  • ltdonutsgt
  • ltjellygtgrapelt/jellygt
  • ltlemongtsourlt/lemongt
  • ltlemongtreal sourlt/lemongt
  • ltglazedgtchocolatelt/glazedgt
  • lt/donutsgt

53
In validator files are in myexamples directory
54
Pastry.xml in xml validator
55
content specification
  • An element may contain one or more child elements
    as content.
  • Content specification types describe non-element
    content.
  • Theses consist of ANY, EMPTY and mixed content.
  • Empty elements do not contain character data or
    child elements. An empty element specification
    like
  • lt!ELEMENT nest EMPTYgt could be marked up as
  • ltnest/gt. Recall the shorthand /gt may be used for
    an empty element closetag.
  • , and cant be used with mixed content
    elements containing only PCDATA. If mixed
    content may contain PCDATA, then this must be
    listed first.
  • An element of type ANY may contain any content
    including PCDATA, or combinations of elements and
    PCDATA. They may also be empty.

56
Mixed content
  • ltELEMENT mymessage (PCDATAmessage)gt
  • Declares mymessage to have mixed content. PCDATA
    must be listed first in mixed content. means
    mymessage may contain nothing or any number of
    occurences of PCDATA and message elements. This
    would be legal markup
  • ltmymessagegthere is an example of the dtd above
  • ltmessagegtthis is a messagelt/messagegt
  • ltmessagegtand anotherlt/messagegt
  • lt/mymessagegt

57
Internal dtd
  • An xml document is standalone if it does not
    reference an external subset.
  • lt?xml version "1.0" standalone "yes"?gt
  • lt!-- Fig. 6.5 mixed.xml --gt
  • lt!-- Mixed content type elements --gt
  • lt!DOCTYPE format
  • lt!ELEMENT format ( PCDATA bold italic )gt
  • lt!ELEMENT bold ( PCDATA )gt
  • lt!ELEMENT italic ( PCDATA )gt
  • gt
  • ltformatgt
  • This is a simple formatted sentence.
  • ltboldgtI have tried bold.lt/boldgt
  • ltitalicgtI have tried italic.lt/italicgt
  • Now what?
  • lt/formatgt

58
In ms xml validator
59
Element group
  • lt!ELEMENT courselist (department, (coursenumber,
    coursedescription))gt
  • Above, a courselist contains a single department
    followed by any number of coursenumber,
    coursedescription pairs.
  • What does the following mean?
  • lt!ELEMENT course (coursenumber, (sectionnumber,
    instructor, roomnumber))gt

60
Attribute specification
  • An attribute specification specifies an attribute
    list for an element via ATTLIST declaration
  • lt!ELEMENT x EMPTYgt
  • ltATTLIST x y CDATA REQUIREDgt
  • Here, y is a required attribute of element x. y
    may contain any char data (except lt,gt, , and
    ).
  • CDATA in an attribute declaration has different
    meaning than a CDATA section in an XML document
    where gt (end tag) may not appear.

61
Using attributes
  • lt?xml version "1.0"?gt
  • lt!-- Fig. 6.7 intro2.xml --gt
  • lt!-- Declaring attributes --gt
  • lt!DOCTYPE myMessage
  • lt!ELEMENT myMessage ( message )gt
  • lt!ELEMENT message ( PCDATA )gt
  • lt!ATTLIST message id CDATA REQUIREDgt
  • gt
  • ltmyMessagegt
  • ltmessage id "445"gt
  • Welcome to XML!
  • lt/messagegt
  • lt/myMessagegt

62
Document with attributes in MS validator
63
Attribute defaults
  • Page authors can specify default values for
    attributes.
  • The keywords are IMPLIED, REQUIRED and FIXED.
  • An implied attribute, if missing, can be replaced
    by any value the application using the document
    wishes.
  • A required attribute must appear or the document
    is not valid.
  • A fixed attribute must have the specific value
    provided.
  • ltmessagegtnumberlt/messagegt does not conform to
    lt!ATTLIST message number CDATA REQUIREDgt
  • lt!ATTLIST address zip FIXED 13820gt specifies
    that zip can only have value 13820 and an
    application processing an XML document with
    address element missing attribute zip would be
    passed this default zip value.

64
Attributes
  • Attribute types may be CDATA (Strings), tokenized
    or enumerated.
  • Strings have no constraints beyond prohibiting
    lt,gt,,,and . Entity references must be used
    for these.
  • Tokenization imposes constraints on attribute
    values such as which characters are permitted in
    an attribute name.
  • An enumerated attribute has a restricted value
    range It can only take on one of the values
    listed in the attribute declaration.

65
tokenized attribute
  • 4 tokenized types exist
  • ID
  • IDREF
  • ENTITY
  • NMTOKEN
  • ID uniquely identifies an element.
  • IDREF attributes point to elements with ID
    attribute.
  • A validating parser verifies that each ID
    attribute type referenced by an IDREF is in the
    document.
  • Using the same value for multiple ID attributes
    is an error.
  • Declaring attributes of type ID to be FIXED is
    an error.

66
Using ID and IDREF attributes
  • lt?xml version "1.0"?gt
  • lt!-- IDExample.xml Example for ID
    and IDREF values of attributes --gt
  • lt!DOCTYPE bookstore
  • lt!ELEMENT bookstore ( shipping, book )gt
  • lt!ELEMENT shipping ( duration )gt
  • lt!ATTLIST shipping shipID ID REQUIREDgt
  • lt!ELEMENT book ( PCDATA )gt
  • lt!ATTLIST book shippedBy IDREF IMPLIEDgt
  • lt!ELEMENT duration ( PCDATA )gtgt
  • ltbookstoregt
  • ltshipping shipID "s1"gt
  • ltdurationgt2 to 4 dayslt/durationgt
  • lt/shippinggt
  • ltshipping shipID "s2"gt
  • ltdurationgt1 daylt/durationgt
  • lt/shippinggt
  • ltbook shippedBy "s2"gt
  • Java How to Program 3rd edition.
  • lt/bookgt

67
In MS Validator
  • Use URL http//employees.oneonta.edu/higgindm/int
    ernet20programming/validate_js.htm
  • with file examples\ch06\IDExample.xml

68
ID example
69
id example internal subset
  • lt?xml version "1.0"?gt
  • lt!-- Fig. 6.8 IDExample.xml
    --gt
  • lt!-- Example for ID and IDREF values of
    attributes --gt
  • lt!DOCTYPE bookstore
  • lt!ELEMENT bookstore ( shipping, book )gt
  • lt!ELEMENT shipping ( duration )gt
  • lt!ATTLIST shipping shipID ID REQUIREDgt
  • lt!ELEMENT book ( PCDATA )gt
  • lt!ATTLIST book shippedBy IDREF IMPLIEDgt
  • lt!ELEMENT duration ( PCDATA )gt
  • gt

70
Idexample.xml continued
  • ltbookstoregt
  • ltshipping shipID "s1"gt
  • ltdurationgt2 to 4 dayslt/durationgt
  • lt/shippinggt
  • ltshipping shipID "s2"gt
  • ltdurationgt1 daylt/durationgt
  • lt/shippinggt
  • ltbook shippedBy "s2"gt
  • Java How to Program 3rd edition.
  • lt/bookgt
  • ltbook shippedBy "s2"gt
  • C How to Program 3rd edition.
  • lt/bookgt
  • ltbook shippedBy "s1"gt
  • C How to Program 3rd edition.
  • lt/bookgt
  • lt/bookstoregt

71
remarks
  • It is an error not to begin a type attribute IDs
    value with a letter, underscore or colon.
  • Providing more than one ID attribute type for an
    element is an error.
  • Referencing a value as an ID is not defined is an
    error.

72
IDExample2.xml (note s3 shippedBy value)
  • ltbookstoregt
  • ltshipping shipID "s1"gt
  • ltdurationgt2 to 4 dayslt/durationgt
  • lt/shippinggt
  • ltshipping shipID "s2"gt
  • ltdurationgt1 daylt/durationgt
  • lt/shippinggt
  • ltbook shippedBy "s2"gt
  • Java How to Program 3rd edition.
  • lt/bookgt
  • ltbook shippedBy "s2"gt
  • C How to Program 3rd edition.
  • lt/bookgt
  • ltbook shippedBy "s3"gt
  • C How to Program 3rd edition.
  • lt/bookgt
  • lt/bookstoregt

73
IDExample2.xml in Validator
74
Entities
  • As we saw in chapter 5 entity references in an
    xml document are replaced by the entity values
    found in the dtd.
  • We saw this for lang.xml and lang.dtd where assoc
    and text entities were replaced with Arabic
    script.
  • Here is another example. Entity city is replaced.

75
entityexample.xml
  • lt?xml version "1.0"?gt
  • lt!-- Fig. 6.10 entityExample.xml --gt
  • lt!-- ENTITY and ENTITY attribute types --gt
  • lt!DOCTYPE database
  • lt!NOTATION html SYSTEM "iexplorer"gt
  • lt!ENTITY city SYSTEM "tour.html" NDATA htmlgt
  • lt!ELEMENT database ( company )gt
  • lt!ELEMENT company ( name )gt
  • lt!ATTLIST company tour ENTITY REQUIREDgt
  • lt!ELEMENT name ( PCDATA )gt
  • gt
  • ltdatabasegt
  • ltcompany tour "city"gt
  • ltnamegtDeitel amp Associates, Inc.lt/namegt
  • lt/companygt
  • lt/databasegt

76
entityexample.xml
77
entityexample.xml
  • Here line 7 ltNOTATIO indicates that an
    application may wish to run IE and load tour.html
    to handle unparsed entities.
  • line 8 declares an entity named city which refers
    to the external document tour.html.
  • NDATA in this line indicates that the content of
    this entity is not xml and supplies the name of
    the notation (html) for this entity.

78
ENTITIES
  • ENTITIES keyword can be used in a dtd to indicate
    that an attribute has mutliple entities for its
    value.
  • lt!ATTLIST directory file ENTITIES REQUIREDgt
  • Specifies that file must contain multiple
    entities. Conforming markup is
  • ltdirectory file animations graphics tablesgt
  • animations, graphics and tables are entities
    declared in a dtd.
  • NMTOKEN type is more restrictive, containing
    letters, digits, periods, underscores, hyphens
    and colons.
  • lt!ATTLIST mathdept phonenum NMTOKEN REQUIREDgt
    might have conforming markup
  • ltmathdept phonenum 607-436-3708gt
  • ltmathdept phonenum 607 436 3708gt does not
    conform because spaces are not allowed.
  • NMTOKENS attribute type would allow multiple
    string tokens separated by blanks.
Write a Comment
User Comments (0)
About PowerShow.com