1 / 16

CIS 451: XML DTDs

CIS 451: XML DTDs. Dr. Ralph D. Westfall February, 2009. Additional XML Issues. what is a "well-formed" XML document? what is a "valid" XML document? what is a DTD? how do you create DTDs?. Well-Formed XML Document. <textbooks> <book>Great Gatsby</book> </textbooks>

tokala
Download Presentation

CIS 451: XML DTDs

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. CIS 451: XML DTDs Dr. Ralph D. Westfall February, 2009

  2. Additional XML Issues • what is a "well-formed" XML document? • what is a "valid" XML document? • what is a DTD? • how do you create DTDs?

  3. Well-Formed XML Document • <textbooks> • <book>Great Gatsby</book> • </textbooks> • a uniquely named root element • one or more elements • elements are properly nested • inner tags always closed before outer ones

  4. Well-Formed Document - 2 • complies with XML rules • for example: has "legal" characters • regular alphanumeric characters • &#_ _ _ ; special characters identified by decimal #s (like &60; = &lt; in HTML) • &#x_ _ _ _ _ _ ; hexadecimal #s (0-f) • other files pulled into document must also be well-formed (e.g., stylesheets)

  5. Valid XML Document • must be a well-formed document • must also comply with "rules" in a data type definition (DTD) • DTD contains specifications ("rules") created by user • user creates both rules and XML document tags • if you don't like the rules, change them!!

  6. Creating a DTD • separate file (use .dtd extension, not .xml) • DTD can be in same file, but separate is much better • all elements defined by <!ELEMENT … > • DTD starts with a root element, which contains other elements • remaining elements either contain more elements, or specifications for type of data

  7. Creating a DTD - Start • <?xml version="1.0"?><!--slsrcpt.xml.doc--> • make sure that you: • put <?xml etc. at top of .dtd file • don't put <!DOCTYPE etc. in .dtd file • error if <!DOCTYPE is in both .xml and .dtd files • put <!DOCTYPE in .xml file instead, e.g.<!DOCTYPE books SYSTEM "books.dtd"> • identifies DOCTYPE (root element) and pulls in .dtd file (like an include or a reference to an external stylesheet)

  8. Creating a DTD - Root • <!ELEMENT textbooks (book+)> • textbooks is "root" element • textbooks element contains at least one book element • + means one or more • (like in regular expressions) • similar spelling is NOT necessary e.g., could have texts element as root

  9. Creating a DTD - Children • <!ELEMENT book (title, ISBN, authors, description?, price+)> • book element contains 5 elements • description element can be absent • ? means optional (once or not at all) • (just like in regular expressions) • how many times does price appear?

  10. Creating a DTD - Data • <!ELEMENT title (#PCDATA)> • title element contains PC (parsed character) data • e.g., the .xml file has following line <title>ASP.NET 1.0</title> • the text between the tags is the data

  11. Creating a DTD - Empty • <!ELEMENT price EMPTY> • price is an "empty" element (no data) • empty element can have attributes (next page) • can also have an effect (cf. HTML <br/> effect) • 2 ways to close elements (empty or not) • <price></price> (always have to close) • <price /> (abbreviated like in ASP form)

  12. Creating a DTD - Attributes • <!ATTLIST price • US CDATA #REQUIRED> • identifies 1 or more attributes, as follows: • element nameprice • attribute nameUS • typeCDATA(character data) • default#REQUIRED (other options) • better if attribute list is just below the corresponding element (but not required)

  13. Creating a DTD - Declarations • element declaration symbols ( ) group of items(title, ISBN, authors) , comma means exact order (a, b, c) a b c | pipe means any order (a | b | c) c b a ok ? once or not at all * zero to many times + one to many times (no symbol) means exactly one time

  14. Put DTD Link into XML File • 2nd line of file • replace [name of] with actual filename <?xml version="1.0"?> <!DOCTYPE syllabus SYSTEM "[name of].dtd"> <?xml:stylesheet href="[name of].css" type="text/css"?>

  15. Exercise • modify the slsrcpt.xml.doc file (or your file) • create .dtd file to match this file's pattern • can use syllabus2.dtd.doc as a sample pattern • put a link to slsrcpt.dtd file in slsrcpt.xml • test with a VBScriptfile (or use xmlint.exe) • xmlint [file].xml (in DOS) • put xmlint.exe and slsrcpt.xml in same directory • now correct your errors

  16. Sample Form

More Related