Presentation is loading. Please wait.

Presentation is loading. Please wait.

Hands-on XML 1® GvdS Palstar 2001 Begrijpen van XML Gert van der Steen Palstar bv University of Utrecht.

Similar presentations


Presentation on theme: "Hands-on XML 1® GvdS Palstar 2001 Begrijpen van XML Gert van der Steen Palstar bv University of Utrecht."— Presentation transcript:

1 Hands-on XML 1® GvdS Palstar 2001 Begrijpen van XML Gert van der Steen Palstar bv University of Utrecht

2 Hands-on XML 2® GvdS Palstar 2001 Understanding XML Elements Entities Attributes Miscelaneous

3 Hands-on XML 3® GvdS Palstar 2001 Elements Keyword Element name Content model Model group Syntax: XML name: any length case sensitive contains letters, digits and punctuation ‘.’ ‘-’ ‘_’ ‘:’ starts with a letter

4 Hands-on XML 4® GvdS Palstar 2001 Element declarations: operators If A and B are model groups: A, BA followed by B A | Beither A or B A?optional A: zero or one A+one or more A A*zero or more A ( A )grouping of A

5 Hands-on XML 5® GvdS Palstar 2001 (SCOC) 'SEQUENCE CONNECTOR' AND 'OR CONNECTOR' Why: Alternative Sequences ex. 1a. DTD: c. DOC: Text for a...b....c1..

6 Hands-on XML 6® GvdS Palstar 2001 (SCOC) 'SEQUENCE CONNECTOR' AND 'OR CONNECTOR' Why: Alternative Sequences ex. 1a DTD: b Syntax diagram: scoc1 = a b c c. DOC:..a1....c1..

7 Hands-on XML 7® GvdS Palstar 2001 (SCOC) 'SEQUENCE CONNECTOR' AND 'OR CONNECTOR' Why: Alternative Sequences ex. 1a DTD: b Syntax diagram: scoc1 = a b c c. DOC:..a1....c1..

8 Hands-on XML 8® GvdS Palstar 2001 (SCOC) 'SEQUENCE CONNECTOR' AND 'OR CONNECTOR' (continued) c. DOC:..a1....c1.. b Syntax diagram: scoc2 = ex. 2a DTD: <!element scoc2 ( (a | b), c)> c a b

9 Hands-on XML 9® GvdS Palstar 2001 (SCOC) 'SEQUENCE CONNECTOR' AND 'OR CONNECTOR' (continued) c. DOC:..b1....b2.. b Syntax diagram: scoc3 = ex. 3a DTD: a b b c

10 Hands-on XML 10® GvdS Palstar 2001 (OI) 'OCCURRENCE INDICATOR' Why: To Repeat Elements ex. 1 a DTD: b1 Syntax diagram: oi1 = d c1a DOC:..a1....a2......d1.... c1b DOC:..a1....b1....b2........d1.. c2 DOC: Correct, minimally, the following input:.. b1....c1....c2..>..d1.. c3 Construct some input and parse a b c

11 Hands-on XML 11® GvdS Palstar 2001 (OI) 'OCCURRENCE INDICATOR' (CONTINUED) ex. 2 a1 DTD: a2 DTD: b2 Construct Syntax Diagrams for oi2 and oi3 Will oi2 and oi3 accept the same input?

12 Hands-on XML 12® GvdS Palstar 2001 (OI) 'OCCURRENCE INDICATOR' (CONTINUED) a DTD: <!element oi4 ( ( a?, b+)*, (c, d? )+ ) b Syntax Diagram oi4= b3 Which elements are permissable before and after b? And for c? (Use next sheet and check with editor) c1 DOC:..c1.. DOC:..b1....b2....c1....d1....c2.. DOC:..a1....b1....c1.. c2 DOC: Correct, minimally, the following input:..a1....c1.. and parse c3 Construct some more input and parse > a bcd ex. 3

13 Hands-on XML 13® GvdS Palstar 2001 Exercise sheet

14 Hands-on XML 14® GvdS Palstar 2001 (OI) 'OCCURRENCE INDICATOR' (CONTINUED) ex. 4 a1 DTD: a2 DTD: b2 Construct Syntax Diagrams for x1 and x2 Will x1 and x2 accept the same input?

15 Hands-on XML 15® GvdS Palstar 2001 (OIOC) 'OCCURENCE INDICATOR' AND 'OR CONNECTOR' ex. 1 a DTD: b1 Syntax Diagram oioc1 = a b c b3 Which elements are permissable before and after a, b, and c? (Use next sheet and check with editor) c3 Construct some input and parse

16 Hands-on XML 16® GvdS Palstar 2001 Exercise sheet

17 Hands-on XML 17® GvdS Palstar 2001 ex.2 a DTD: b2 Construct the Syntax Diagram c3 Construct some input and parse (OIOC) 'OCCURENCE INDICATOR' AND 'OR CONNECTOR' (CONT)

18 Hands-on XML 18® GvdS Palstar 2001 (NE) 'NESTING ELEMENTS' ex. a DTD: DTD: b1 Syntax Diagram ne1 = l1 = c1 DOC:..a1....b1.. a l1 b

19 Hands-on XML 19® GvdS Palstar 2001 (RE) 'RECURSIVE ELEMENTS' ex. 1 a DTD: !element re1 ( (a, re1, b) | c) > b Syntax Diagram re1 = a - re1 - b c c1 DOC:..a1....a2....c1....b2....b1.. c2 DOC:..c1..

20 Hands-on XML 20® GvdS Palstar 2001 (RE) 'RECURSIVE ELEMENTS' (CONTINUED) ex.2 a DTD: c1 DOC: Europe Netherlands Amsterdam Zeist England Swindon c3 Add streets by another nesting of l and try out

21 Hands-on XML 21® GvdS Palstar 2001 ’DETERMINISTIC' Why: A content model must be deterministic (SGML: “not ambiguous”) ex. 1 a DTD: DTD: b1 Syntax Diagrams am1 = Syntax diagrams am2 = In XML, am2 is deterministic, am1 not a - b a - c b c a

22 Hands-on XML 22® GvdS Palstar 2001 ’DETERMINISTIC' (CONTINUED) ex. 2 a DTD: b1 Syntax Diagram am3 = c b b3 Is content model deterministic? a1a1 a2a2

23 Hands-on XML 23® GvdS Palstar 2001 COMMENT DECLARATION Between other declarations in the DTD Between other text in the DOC Can be any lenght...

24 Hands-on XML 24® GvdS Palstar 2001 Why: to process text for entity references and to be sensitive to the appearance of tags ex. a DTD: c1 DOC: the character entity Ä is processed within pcdata, also " " will be treated #PCDATA (PARSED CHARACTER DATA)

25 Hands-on XML 25® GvdS Palstar 2001 CDATA ( CHARACTER DATA) Why: to keep text literally ex. DTD: no special declaration required DOC: The character entity <![CDATA [Ä is not processed within CDATA, also " "]]> will not be treated.

26 Hands-on XML 26® GvdS Palstar 2001 Mixed content model Why: Allows for “floating” or “in-line” elements in between text Syntax in DTD: restricted to #PCDATA alternating with subelements DTD: – DOC: – Clean with an alcoholic flammable substance

27 Hands-on XML 27® GvdS Palstar 2001 Preserved space Within #PCDATA white space will be normalized to a single character With the reserved attribute ‘xml:space’ the white space will be preserved DOC: O --I-- I / \

28 Hands-on XML 28® GvdS Palstar 2001 Language attribute With the reserved attribute ‘xml:lang’ the natural language of the contained #PCDATA is encoded The values of the attribute are language identifiers as defined by [RFC1766], “Tags for the Identification of Languages” DOC: What colour is it? What color is it?

29 Hands-on XML 29® GvdS Palstar 2001 EMPTY Why: 1. to refer to objects which are internal or external to the document 2. To trigger special processing DTD: DOC:...The page will break here... or:...The page will break here...

30 Hands-on XML 30® GvdS Palstar 2001 Entities for DTD: for DOC: Keyword Entity name Replacement Syntax:

31 Hands-on XML 31® GvdS Palstar 2001 Entities Entity references are requests for data to be imbedded at the point of reference In a Document: –Internal text entities: simple text replacement –External text entities: inclusion of an external document –Binary entities: reference to multimedia files –Character defining entities: for characters outside the default characterset –Built-in entities: for characters used in markup –Character entities: the number of a character in the default characterset In a DTD: –Parameter entities: simple text replacement

32 Hands-on XML 32® GvdS Palstar 2001 Internal text entities Purpose: simple text replacement; text stored in entity DTD: – DOC: –... the &gca; sponsor meetings... –==>... the Graphics Communications Association sponsor meetings...

33 Hands-on XML 33® GvdS Palstar 2001 External text entities Purpose: inclusion of an external document; reference stored in entity DTD: – DOC: – a book about xml &ch1;... more content...

34 Hands-on XML 34® GvdS Palstar 2001 Binary entities Purpose: reference to multimedia files (“Non-XML data”) Syntax in DTD: – DTD – DOC – As is shown in the following diagram: –wrong: As is shown in the following diagram: &figure1;

35 Hands-on XML 35® GvdS Palstar 2001 Character defining entities Purpose: for characters outside the default characterset DTD: – –%ISOnum; file isonum.ent: – –... DOC: –..about ¾ of the height.. –=>..about ¾ of the height..

36 Hands-on XML 36® GvdS Palstar 2001 Character entities Purpose: hard coding of characters, e.g. for UNICODE “©” © DTD: – DOC: &Copyright; –Resolution by parser of "&Copyright ”: " © ” –Resolution by printer/browser of " &#xA9 ”: " © ” Ranges: –&0;.. &255; -- extended ASCII set: ISO 8859/1, used under Windows, Sun Unix and as the Web default –&256;.. &65535; -- Unicode/ISO10646 –larger -- any Unicode character –alternative to decimal: hexadecimal, like © or ￸

37 Hands-on XML 37® GvdS Palstar 2001 XML built-in character entities Purpose: for characters used in markup DTD: no declaration required DOC: –< for ‘<‘ –> for ‘>’ –& for ‘&’ –&apos; for “’’ –" for ‘”’

38 Hands-on XML 38® GvdS Palstar 2001 Parameter entities Purpose: simple text replacement in a DTD –DTD: –==> DTD: Purpose: to keep text literally –DOC:

39 Hands-on XML 39® GvdS Palstar 2001 ATTRIBUTE DECLARATION Why: to associate information with an Element: metadata, hypertext, multimedia, layout (!?),... Syntax: DTD: <!ATTLIST el_name att_name1 type1 default1 att_name2 type2 default2 > Spelling of attribute name: as an XML name (~ element name) Allowed: more than one <!ATTLIST for an element Element name Attribute name Type of attribute Default value

40 Hands-on XML 40® GvdS Palstar 2001 TYPES FOR ATTRIBUTE DECLARED VALUES Type: Attribute value is: CDATASGML character data ENTIT(Y)(IES)( list of) subdocument(s) entity name(s) IDUnique identifier for element IDREF(S)(list of) (a) reference(s) to a previously ID NMTOKEN(S)(list of) name token(s) NOTATIONmember of a list ot notations Name groupone of a finite set

41 Hands-on XML 41® GvdS Palstar 2001 ATTRIBUTE DECLARATION, declared values 1/3 <!ATTLIST memo rev CDATA#REQUIRED size NMTOKEN#REQUIRED projects NMTOKENS#REQUIRED [any character]+ [ letter | 0..9 | - |. | _ | :]+ NMTOKEN, [" ", NMTOKEN]* DTD: DOC: <memo rev="27/1/96 - 3.2a" size=”.17-.19" projects="2-a 3-b" >..... attribute name type default value

42 Hands-on XML 42® GvdS Palstar 2001 ATTRIBUTE DECLARATION, declared values 2/3 <!NOTATION tex PUBLIC "-//local//NOTATION TeX Formula//EN” “c:\programs\show_tex”> <!ATTLIST fig <!ATTLIST figr <!ATTLIST figrs DTD: DOC: file ID ENTITY IDREF #REQUIRED #REQUIRED >refid id IDREFS#REQUIRED >refids

43 Hands-on XML 43® GvdS Palstar 2001 ATTRIBUTE DECLARATION, declared values 3/3 DTD: DOC:... 3 over 4

44 Hands-on XML 44® GvdS Palstar 2001 DEFAULT VALUES FOR ATTRIBUTE DECLARATIONS Reserved Words: FIXED- used for attributes with constant values REQUIRED- demands a user-entered value (always the case when there is no DTD IMPLIED- value supplied by application if not entered explicitly Example default value in DOC:

45 Hands-on XML 45® GvdS Palstar 2001 ATTRIBUTE EXERCISES

46 Hands-on XML 46® GvdS Palstar 2001 CONDITIONAL SECTION in DTD Why: to indicate which parts of a DTD should be selected Example in DTD:...... ]]>......

47 Hands-on XML 47® GvdS Palstar 2001 Processing instructions (“PI”) Why: to contain information that is not part of the document, e.g. to trigger processor functions Can be (mis)used for many purposes. DTD: not required DOC: Here follows a pagebreak

48 Hands-on XML 48® GvdS Palstar 2001 Parsing: Well-formed versus Valid Well-formed –XML declaration required –Tags must be balanced or be an EMPTY tag –All attribute values must be quoted –No markup characters (< or &) in the character data allowed –Properly nested elements –Attributes must be of type CDATA (if no dtd is used) Valid –Well-formed plus conforms to DTD

49 Hands-on XML 49® GvdS Palstar 2001 Parsing sequence External subset Parsing path XML document XML Declaration Document Type Declaration Internal subset Prolog Text + Markup

50 Hands-on XML 50® GvdS Palstar 2001 Concise XML Syntax <!DOCTYPE example SYSTEM “Example.dtd” [ ]> The &XML; format is a very important move to bringing the benefits of structured markup to the masses. &history; The following figure shows a wheelchair: The tags, and are used in this document]]. Example.xml Superficially it looks like HTML because the tags have the same delimiters, < and > --- XML --- | | SGML HTML History.xml <![%figs[<!ENTITY %ExampleContent “par | fig”>]]> Example.dtd XML Declaration Document Type Declaration Internal subset c:/Wheelchair.tif External subset With thanks to Neil Bradley: “The XML Companion”, Addison Wesley Longman, 2nd ed., ISBN 0-201-342855 Prolog

51 Hands-on XML 51® GvdS Palstar 2001 HOW TO WRITE DOCUMENT TYPE DEFINITIONS Left brain: - Makes subdivisions - Results in numbering and hierarchy Right brain: - Makes associations - Results in relations In XML: - Hierarchical structure by rewriting elements in components - Necessary: document analysis - Associative structure by writing attributes to elements - Necessary: inventory of useful relations

52 Hands-on XML 52® GvdS Palstar 2001 DESIGNER OF STRUCTURED DOCUMENTS

53 Hands-on XML 53® GvdS Palstar 2001 Oefeningen in het aanpassen van documenten en DTD’s Breid B.xml uit, o.a. met een lijst Breng modificaties aan in EX.DTD en Ex.xml: –creëer floating elementen “fn” en “fnr” met bij elkaar horende id’s en gebruik deze binnen een ander element, bijv. “Z” dat #PCDATA bevat –kort een bepaalde constructie in EX.DTD af door een parameter entity –vervang een stuk tekst in de invoer door een general entity, te definiëren in de DTD Maak/genereer een documentschema van B.DTD, analoog aan het schema voor het Memo en het Workshop Manual

54 Hands-on XML 54® GvdS Palstar 2001 Oefeningen in het zelf maken van kleine DTD’s Beschrijf de regelmaat in de opgegeven patronen in een content model; test m.b.v. een uitbreiding van EX.DTD en Ex.xml. Teneinde het document kort te houden gebruiken we de volgende element declaraties: etcetera. Het document kan dan bevatten:, etcetera. A. drie documenten: ppqrss pqqs pppqrsss content model: gebruik "(", ")", ",", "+" en "?" B. vier documenten: p pq pqr pqrs content model: gebruik "(", ")", "," en "?" C. vijf documenten: pqp pqr qrp qqp prr content model: gebruik "(", ")", "," en "|"


Download ppt "Hands-on XML 1® GvdS Palstar 2001 Begrijpen van XML Gert van der Steen Palstar bv University of Utrecht."

Similar presentations


Ads by Google