1 / 15

XML Language Family Detailed Examples

XML Language Family Detailed Examples. Most information contained in these slide comes from: h ttp://www.w3.org, http://www.zvon.org/ These slides are intended to be used as a tutorial on XML and related technologies Slide author: Jürgen Mangler (juergen.mangler@univie.ac.at)

maeve
Download Presentation

XML Language Family Detailed Examples

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XML Language FamilyDetailed Examples • Most information contained in these slide comes from: http://www.w3.org, http://www.zvon.org/ • These slides are intended to be used as a tutorial on XML and related technologies • Slide author:Jürgen Mangler (juergen.mangler@univie.ac.at) • This section contains examples on: XML, DTD (Document Type Definition)

  2. The W3C is the "World Wide Web Consortium", a voluntary association of companies and non-profit organizations. Membership is very expensive but confers voting rights. The decisions of W3C are guided by the Advisory Committee, lead by Tim Berners-Lee. The XML recommendation was written by the W3C's XML Working Group (WC), which has since divided into a number of subgroups. The stages in the life of a W3C Recommendation (REC) • Working Draft (maximum gap target: 3 months) • Last Call (public comment invited; W3C must respond) • Candidate Recommendation (design is stable; implementation feedback invited) • Proposed Recommendation (Advisory Committee review)

  3. XML • First line: <?xml version=“1.0” encoding=“...”?> • Elements + Attributes • Wellformed (start/closing tag, correctly nested) • One root element • <& must be escaped • ><&’” can be escaped(&gt; &lt; &amp; quot; &apos;) • Attributes in quotes • Elements start with _ or letters • Elements can consist of alphanumeric characters - _ (no :, don’t start with xml)

  4. An XML document is valid if it has an associated document type definition and if the document complies with the constraints expressed in it. • The document type definition (DTD) must appear before the first element in the document. • The name following the word DOCTYPE in the document type definition must match the name of the root element. tutorial.dtd: <!ELEMENT tutorial (#PCDATA)> tutorial.xml: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE tutorial SYSTEM "tutorial.dtd"><tutorial>This is an XML document</tutorial>

  5. tutorial.dtd: <!ELEMENT gericht (geschmack , farbe)><!ELEMENT geschmack (#PCDATA)><!ELEMENT farbe (#PCDATA)> • An element type has element content if elements of that type contain only child elements (no character data), optionally separated by white space. tutorial.xml: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE gericht SYSTEM "tutorial.dtd"><gericht> <geschmack>fad</geschmack>   <farbe>graubraun</farbe></gericht> tutorial.xml (with errors, farbe missing): <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE gericht SYSTEM "tutorial.dtd"><gericht> <geschmack>Start</geschmack></gericht>

  6. The root element XXX can contain zero or more elements AAA followed by precisely one element BBB. Element BBB must be always present.: • If an element name in the DTD is followed by the star [*], this element can occur zero, once or several times tutorial.dtd: <!ELEMENT wein (geschmack* , farbe)><!ELEMENT geschmack (#PCDATA)><!ELEMENT farbe (#PCDATA)> tutorial.xml: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE wein SYSTEM "tutorial.dtd"><wein> <geschmack>vollmundig</geschmack> <geschmack>herb</geschmack>   <farbe>rot</BBB></wein>

  7. tutorial.dtd: <!ELEMENT wein (geschmack+ , farbe)><!ELEMENT geschmack (#PCDATA)><!ELEMENT farbe (#PCDATA)> • If an element name in the DTD is followed by the plus [+], this element can occur once or several times. tutorial.xml: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE wein SYSTEM "tutorial.dtd"><wein> <geschmack>lieblich</geschmack> <geschmack>blumig</geschmack   <farbe>weiss</farbe></wein> tutorial.xml (with errors, AAA must occur at least once): <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE XXX SYSTEM "tutorial.dtd"><wein>   <farbe>weiss</farbe></wein>

  8. tutorial.dtd: <!ELEMENT bier (brauart? , bewertung)> <!ELEMENT brauart (#PCDATA)><!ELEMENT bewertung (#PCDATA)> • If an element name in the DTD is followed by the question mark [?], this element can occur zero or one times. tutorial.xml: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE bier SYSTEM "tutorial.dtd"><bier>   <bewertung>süffig</bewertung></bier> This example uses a combination of [ + * ?] <!ELEMENT bier (brauart? ,bewertung+)><!ELEMENT brauart (wasser? , hefeart*)><!ELEMENT bewertung (note, kommentar)><!ELEMENT note (#PCDATA)><!ELEMENT kommentar (#PCDATA)> How could a valid document look like?

  9. The root element XXX must contain either one element AAA or one element BBB: • With the character [ | ] you can select one from several elements. test.dtd: <!ELEMENT zum_essen (bier | wein)><!ELEMENT bier (#PCDATA)><!ELEMENT wein (#PCDATA)> test.xml: <!DOCTYPE zum_essen SYSTEM "test.dtd"><zum_essen>   <bier>Ottakringer</bier></zum_essen> test.xml: <!DOCTYPE zum_essen SYSTEM "test.dtd"><zum_essen>   <wein>Riesling</wein></zum_essen> Text can be interspersed with elements. <!ELEMENT zum_essen (bier+ , wein+)><!ELEMENT bier (#PCDATA | geschmack )><!ELEMENT wein (#PCDATA | geschmack )*><!ELEMENT geschmack (#PCDATA)>

  10. Attributes are used to associate name-value pairs with elements. Attribute specifications may appear only within start-tags and empty-element tags. • The declaration starts with !ATTLIST followed by the name of the element (myElement) to which the attributes belong to, followed by the definition of the individual attributes (myAttributeA, myAttributeB). <!ELEMENT myElement (#PCDATA)><!ATTLIST myElement            myAttributeA  CDATA #REQUIRED           myAttributeB  CDATA #IMPLIED> <!DOCTYPE myElement SYSTEM "tutorial.dtd"> <myElement myAttributeA="#d1" myAttributeB="*~*">           Text       </myElement>

  11. An attribute of type CDATA may contain any arbitrary character data, given it conforms to well formedness constraints. • Type NMTOKEN can contain only letters, digits and point [ . ] , hyphen [ - ], underline [ _ ] and colon [ : ] • NMTOKENS can contain the same characters as NMTOKEN plus whitespaces. • White space consists of one or more space characters, carriage returns, line feeds, or tabs. <!ELEMENT taskgroup (#PCDATA)><!ATTLIST  taskgroup  group  CDATA #IMPLIED purpose  NMTOKEN #REQUIRED names  NMTOKENS #REQUIRED> <!DOCTYPE persongroup SYSTEM "tutorial.dtd"><taskgroup group="#RT1" purpose="realisation::T1" names="Joe Max Eddie"/>

  12. The value of an attribute of type ID may contain only characters permitted for NMTOKEN and must start with a letter. • No element type may have more than one ID attribute specified. • The value of an ID attribute must be unique between all values of all ID attributes (in the document!). <!ELEMENT weinkarten (wein+ , restaurant+)>        <!ELEMENT wein (#PCDATA)>        <!ELEMENT restaurant (#PCDATA)>        <!ATTLIST wein sorte ID #REQUIRED>         <!ATTLIST restaurant               name ID #IMPLIED              weine NMTOKEN #IMPLIED> <weinkarten> <wein sorte=“riesling"/>   <wein sorte=“chardonnay"/>   <wein sorte=“schilcher"/>   <restaurant name=“mangler" weine="14 5 8"/></weinkarten>

  13. The value of an attribute of type IDREF has to match the value of some ID attribute in the document. The value of an IDREF attribute can contain several references to elements with ID attributes separated by whitespaces. <!ELEMENT weinkarten (wein+ , restaurant+)><!ELEMENT wein (#PCDATA)><!ELEMENT restaurant (#PCDATA)><!ATTLIST wein sorte ID #REQUIRED><!ATTLIST restaurant  name CDATA #REQUIRED weinsorte IDREF #REQUIRED>        <XXX> <AAA sorte=“riesling"/>   <AAA sorte=“schilcher"/>   <AAA sorte=“madoc"/>   <restaurant name=“derntl” weinsorte=“schilcher" />   <restaurant name=“mangler” weinsorte=“chardonnay riesling" /></XXX>

  14. <!ELEMENT list-of-exams (exam+)>        <!ELEMENT exam (#PCDATA)>        <!ATTLIST exam difficult ( yes | no ) #REQUIRED><!ELEMENT list-of-exams (exam+)>        <!ELEMENT exam (#PCDATA)>        <!ATTLIST exam difficult ( yes | no ) #REQUIRED>         <!ATTLIST exam month (1|2|3|4|5|6|7|8|9|10|11|12) #IMPLIED>      • Permitted attribute values can be defined in the DTD If an attribute is implied, a default value can be provided in case the attribute isn't used. <!ELEMENT list-of-exams (exam+)><!ELEMENT exam (#PCDATA)> <!ATTLIST exam difficult ( yes | no ) "yes"><!ATTLIST exam month NMTOKEN "1"> #Required: You must set the attribute #Implied: You can set the attribute

  15. <!ELEMENT politicians (brain+)><!ELEMENT brain EMPTY><!ATTLIST content true ( yes | no ) "yes"> • An element can be defined as EMPTY. In such a case it may contain attributes only but no text. <politicians> <brain content="yes"/>   <brain content="no"></brain></politicians> <politicians>   <brain true="yes"/>   <brain true="no"></brain>   <brain>      </brain> <brain>money, power</brain></politicians> Are there errors in this example? Where are they?

More Related