Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML Study-Session: Part I Writing a XML Document.

Similar presentations


Presentation on theme: "XML Study-Session: Part I Writing a XML Document."— Presentation transcript:

1 XML Study-Session: Part I Writing a XML Document

2 Objectives: By completing this study-session, you should be able to: n Recognize well-formed XML documents. n Understand basic XML syntax. n Create simple XML documents of your own.

3 XML Elements: The basic components in XML is the element, a piece of text bounded by matching tags. E.g. A Simple Element n Tags must be balanced. n Overlapping elements are prohibited.

4 Example: The following may appear in HTML, but not in XML: This is bold. This is bold italic. This is italic. The correct way to do this in XML: This is bold. This is bold italic. This is italic.

5 XML Elements (contd.): n An element may contain one or more subelements. n The structures between tags are referred to as the content. n The data - i.e. the part not enclosed within brackets - is taken to be the text of the document and is referred to as PCDATA (Parsed Character Data).

6 Example: n Joe Black 35 jb@whitehall.com XML has an abbreviation for empty elements. The following: can be abbreviated to.

7 XML Attributes: XML allows us to associate attributes with elements. In XML, attributes are defined as (name, value) pairs. E.g. 420.12 E.g. n A given attribute may only occur once within a tag, while subelements with the same tag may be repeated.

8 Well-formed XML: A document is considered well-formed if: n Tags nest properly. n Attributes are unique. This ensures that the XML data will parse into a labeled tree.

9 Example: person nameage e-mail Joe Black35jb@whitehall. com

10 Rules of thumb: n XML document must contain one or more elements. n There is exactly one element, called the root or document element, which encapsulates all content. n Tag names are case sensitive. n Tag names must begin with a letter, and contain letters, digits, hypens, undescores, colons (reserved for name-spaces), or full-stops. n The string “XML” (any case) is reserved.

11 More on attributes: n Attributes and their values can only appear in the start-tag. n Attribute names must begin with a letter, and can consist of letters, digits, hyphens, underscores, and full-stops. Colons are reserved for name-spaces. n Values can be demarcated by single or double quotes. n The ‘<‘ and ‘&’ characters are not permitted in attributes.

12 Anatomy of an XML document: 1. Prolog –this section is optional. –contains: XML declaration (version, encoding, standalone) Comments E.g. Processing instructions (PIs) E.g. Document Type Declarations (DTDs)

13 Anatomy of an XML document: (contd.) 2. Root document –this section is required. –contains: Elements and Attributes Comments Subelements 3. Epilog –this section is optional. –may contain comments and Pis.

14 Example: Jimbo's Super Clock Ever wake up in the morning to discover that your alarm clock didn't go off because the power failed? Or that your roof leaked, it rained, and the stupid thing just plain shorted out when it got wet? Now you don't have to worry about waking up two hours after you were supposed to be at work. Our latest, greatest Super Clock is a dream come true. It plugs into the wall but has its own set of batteries and protection from short circuits. The batteries even warn you when they're starting to fade - and they come with a twenty-five year guarantee! This clock is completely watertight, a sealed sphere of time in a stainless steel case. The clock face is large enough to read from a distance, and lights up with a touch for those nights when you're stumbling in the dark. The alarm starts off quiet, but gets louder and louder when you don't turn it off - guaranteed to wake even the soundest sleepers. Snooze features let you sleep just a little bit more, but it won't let you sleep in for more than an hour past the alarm. This clock is ready to adorn your bedroom, and even includes connections for lamp controls to brighten your morning, and electroshock clips for those who can't wake up any other way.

15 Example: (contd.) Jimbo's Super Clock : SC45-A $199.95 ( $19.95 freight/air, $7.95 ground) Twenty-five year Warranty. Made in Canada Lamp Controller : LC45-X $25.95 ( $9.95 freight/air, $4.95 ground) Ten year Warranty. Made in Canada Electroshock Clips : ES45-L $59.95 ( $9.95 freight/air, $4.95 ground) One-year warranty. Made in USA

16 Built-in and Character Entities: The following built-in entities can be used in character data and also in attribute values when necessary: EntityValueExampleParsed Result <Less than (<)3 < 53 < 5 >Greater than (>)12 > 812 > 8 &Amperand (&)AT&TAT&T &apos;Apostrophe (‘)ain&apos;tain’t "Quote (“)&quotWhy?&quot“Why?” Note: The &apos; and " entities are only needed in attributes.

17 Creating general Entities: You can define your own entities just as you define elements. The syntax for defining an entity is : n The name must be composed of letters, digits, periods, dashes, underscores, or colon, and begin with a letter or underscore. The syntax to use an entity in the markup is: &Name; n E.g. &ProdName; is a remarkable advance, guaranteeing users happier days.

18 CDATA marked sections: CDATA sections make it possible to encode content that uses markup characters for other meaning. The syntax is : n E.g. XML uses tags, which look like,, AND ]]> to mark up content. The only content which may not appear in the CDATA contents is the closing string ]]>.

19 Next session: Validating XML Documents n Creating your own DTDs n Using XML-Schema


Download ppt "XML Study-Session: Part I Writing a XML Document."

Similar presentations


Ads by Google