Presentation is loading. Please wait.

Presentation is loading. Please wait.

An Introduction to XML Based on the W3C XML Recommendations.

Similar presentations

Presentation on theme: "An Introduction to XML Based on the W3C XML Recommendations."— Presentation transcript:

1 An Introduction to XML Based on the W3C XML Recommendations

2 Agenda XML Syntax –XML vs HTML –Data Types – Elements, Attributes –White Space – Optional, Mandatory, & Preserved –Empty Content –Valid vs Well Formed XML Schema –Used to Validate XML data –Before XML Schema – DTD’s –Simple Types vs Complex Types –Restricting data with Regular Expressions Namespaces –Avoiding Tag Name Conflicts XML Tools –XML Spy and Other Tools Corresponding Sample XML, XSD, DTD, XSL, and XHTML files XML Resources on the web – - an excellent site – –

3 XML vs HTML As you can see, XML looks similar to HTML. Data

4 XML vs HTML Unlike HMTL: –XML is Case Sensitive –Tags must be properly nested –All start tags must have a corresponding end tag to close the element –All XML documents must have a root element –Attrbutes must use quotes (can be single or double) –White space between tags is preserved

5 XML vs HTML Special Characters –Handled the same way –For Example: ‘ “ & < > &apos; " &

6 Elements XML Elements are extensible and they have parent/child relationships. XML elements must follow these naming rules: –Names can contain letters, numbers, underscores, periods, colons, and hyphens (last three are not normally used in element names) –Names must not start with a number or punctuation character –Names must not start with the letters xml (or XML or Xml ) –Names cannot contain spaces

7 Attributes Attributes are normally used to store metadata, data about data, and the real data is stored in elements between the start and end tags. Single or Double quotes can be used.

8 White Space White Space Includes: –Carrage returns, Line feeds, Spaces, Horizontal Tabs Optional White Space –White space is optional in XML files Mandatory White Space –White Space must occur when using attributes Preserved White Space –Between start/end tag pairs

9 Optional White Space Valid Data Valid Data

10 Mandatory White Space Valid Invalid Must have white space here

11 Preserved White Space Valid White space between start/end tag pairs will be preserved

12 Empty Content IF no data is “held” between a start/ end tag pair, two formats may be used: The second format is called an Empty Tag (aka Null tag) and commonly used when only an attribute is needed:

13 Valid vs Well Formed XML data is defined and validated most commonly by: –XML Schemas –DTD’s (Document Type Definition) XML data is well formed if it follows the W3C XML Recommendation, Version 1.0 –This includes: The start/end tags matching up White space used properly NOTE: XML Spy does both checks

14 XML Schema Used to Define and Validate XML –In order for the XML file to be validated by a schema, the schema’s location is referenced as an attribute of the root element <FirmOrder … schemaLocation=" C:\13.0\Documentation\xsd\firmOrder.xsd"/>

15 XML Schema Before XML Schema, most XML documents were validated against a DTD <xsd:schema xmlns:xsd="" targetNamespace="" xmlns="" elementFormDefault="qualified"> DTD XML Schema Mercator Type Tree

16 XML Schema Element Data Types –XML Schema’s Simple Types Similar to Items in Mercator 44 Simple types built-in XML Schema –XML Schema’s Complex Types Similar to Groups in Mercator 36 Complex types built-in XML Schema –XML Schema’s Attributes Similar to the Properties of Items and Groups in Mercator

17 XML Schema Simple Types can be restricted using Regular Expressions:

18 Namespaces XML Namespaces provide a method to avoid element name conflicts. –Since element names are not predefined as in HTML, often times a name conflict can occur when combining two different documents using the same name for two different elements

19 Namespaces, cont. If the following two XML documents were added together, there would be an element name conflict because both documents contain a element with different content and definition. Tea Table 80 120 Apples Bananas

20 Solving Name Conflicts using a Prefix Apples Bananas African Coffee Table 80 120

21 Using Namespaces Apples Bananas African Coffee Table 80 120

22 Namespaces URI’s are used as the namespace name –Most commonly used URI is a URL –URL’s by definition are unique to companies –The URL does NOT need to be valid They are used for creating uniqueness not validating your tags Most companies put “help” documentation about their namespace, tags, and/or XML Schemas

23 XML Samples The next five slides have different types of XML files that correspond to each other: –XML Data Document –XML Schema –DTD (these are not written in XML) –XSL – style sheet

24 XML Data Sample Optional name tag used in this child tag First description start/end tag pair in child tag Optional name tag used in this child tag First description start/end tag pair in child tag Second description start/end tag pair in child tag

25 XML Schema Sample <xsd:schema xmlns:xsd="" targetNamespace="" xmlns="" elementFormDefault="qualified">

26 XML DTD Sample

27 Style Sheet (XSL) Sample XHTML Sample Name Description

28 XHTML Generated XHTML Sample Name Description Optional name tag used in this child tag First description start/end tag pair in child tag Optional name tag used in this child tag First description start/end tag pair in child tag

29 XML Spy Accomplishes several XML tasks including: –Editing a variety of XML data graphically –Allowing multiple views including: Text, browser, grid, structure (schema design), –Creates test data from XML Schemas –Generates XML Schemas from XML files –Validates data –Checks data for Well-formedness

30 Other Tools Internet Explorer –Displays XML data using a default style sheet –Checks XML for Well-formedness and displays error message for troubleshooting UltraEdit

31 XML Resources on the web They are hundreds of XML resources on the web. – (an excellent site) – – The easiest was to find data about a specific XML topic or syntax is to type it into

32 Contact Us Barry DeBruin 919-434-5399

Download ppt "An Introduction to XML Based on the W3C XML Recommendations."

Similar presentations

Ads by Google