Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML 1 Enterprise Applications CE00465-M XML. 2 Enterprise Applications CE00465-M XML Overview Extensible Mark-up Language (XML) is a meta-language that.

Similar presentations


Presentation on theme: "XML 1 Enterprise Applications CE00465-M XML. 2 Enterprise Applications CE00465-M XML Overview Extensible Mark-up Language (XML) is a meta-language that."— Presentation transcript:

1 XML 1 Enterprise Applications CE00465-M XML

2 2 Enterprise Applications CE00465-M XML Overview Extensible Mark-up Language (XML) is a meta-language that describes the content of the document (self-describing data) Java = Portable Programs XML = Portable Data XML does not specify the tag set or grammar of the language –Tag Set: mark-up tags that have meaning to a language processor –Grammar: defines correct usage of a language’s tags

3 XML 3 Enterprise Applications CE00465-M Applications of XML Configuration files –Used extensively in J2EE architectures Media for data interchange –A better alternative to proprietary data formats Business-to-business (B2B) transactions on the Web –Electronic business orders (ebXML) –Financial Exchange (IFX) –Messaging exchange (SOAP)

4 XML 4 Enterprise Applications CE00465-M XML versus HTML XML fundamentally separates content (data and language) from presentation; HTML allows a mix of content and presentation HTML explicitly defines a set of legal tags as well as the grammar (intended meaning) – … XML allows any tags or grammar to be used hence eXtensible – … Note: Both are based on Standard Generalized Markup Language (SGML)

5 XML 5 Enterprise Applications CE00465-M Simple XML Example Student.xml 2 Harry Nelson 250 2005-09-28 Computer Science VP

6 XML 6 Enterprise Applications CE00465-M Parsers & well-formed XML Documents A software program called an XML parser (or an XML processor) is required to process an XML document –Parser reads the documents, checks its syntax and reports any errors –XML documents are well formed if they are syntactically correct –XML documents requires a single root element, start and end tag for each element, properly nested tags and attribute values in quotes –Parsers can support either the Document Object Model (DOM) and/or Simple API for XML (SAX)

7 XML 7 Enterprise Applications CE00465-M XML Components Prolog –Defines the xml version, entity definitions and DOCTYPE Components of the document –Tags and attributes –CDATA (character data) –Entities –Processing instructions –Comments

8 XML 8 Enterprise Applications CE00465-M XML prolog XML Files always start with a prolog –The version of XML is required –The encoding identifies the character set –The prolog can contain entities and DTD definitions

9 XML 9 Enterprise Applications CE00465-M Document Type Definitions (DTDs) Introduced into an XML document by !DOCTYPE statement –DTDs define an XML document’s structure (i.e. what elements are allowed in the document) –An XML document doesn’t have to have a DTD –But are often recommended to ensure document conformity especially in B2B transactions Parsers are classified as validating or non-validating. Validating parsers check the XML document against the DTD –If the XML document conforms to the DTD it is said to be valid –If it fails to conform to the DTD but is syntactically correct it is said to be well formed –A valid document must also be well formed

10 XML 10 Enterprise Applications CE00465-M Example of a DTD Student.dtd

11 XML 11 Enterprise Applications CE00465-M Defining Elements <!ELEMENT XmlStudent (img,StdNo,FirstName,LastName,Phone,StartDate, Award,Faculty)> Types –EMPTY Element cannot contain any text or child elements –#PCDATA Only character data permitted –ANY Any well-formed XML data – List of legal child elements (no character data) – May contain character data and/or child elements (cannot define order and number of child elements)

12 XML 12 Enterprise Applications CE00465-M Defining Elements Cardinality –[none]Default (one and only one instance) –?0,1 –*0,1,…..,N –+1,2,…..,N List Operators –,Sequence (in order) –|Choice (one of several)

13 XML 13 Enterprise Applications CE00465-M Grouping Elements Set of elements can be grouped within parentheses –(Elem1?, Elem2?)+ Elem1 can occur 0 or 1 times followed by 0 or 1 occurrences of Elem2 The group (sequence) must occur 1 or more times OR –((Elem1, Elem2) | Elem3)* Either the group of Elem1, Elem2 is present (in order) or Elem3 is present, 0 or more times

14 XML 14 Enterprise Applications CE00465-M <!DOCTYPE Person[ <!ELEMENT Person ( (Mr|Ms|Miss)?, FirstName, MiddleName*, LastName,(Jr|Sr)? )> ]> Harry Nelson Element Example Note: The DTD has been embedded in the DOCTYPE, rather than being in a separate file

15 XML 15 Enterprise Applications CE00465-M Defining Attributes Example <!ATTLIST Product cost CDATA #FIXED “200” id CDATA #REQUIRED>

16 XML 16 Enterprise Applications CE00465-M Attribute Types CDATA –Essentially anything; simply unparsed data Enumeration –Attribute(value1|value2|value3)[Modifier] Eight other attribute types –ID,IDREF,NMTOKEN,NMTOKENS,ENTITY,ENTITIES,NOTATION

17 XML 17 Enterprise Applications CE00465-M Attribute Modifiers #IMPLIED –Attribute is not required #REQUIRED –Attribute must be present #FIXED “value” –Attribute is present and always has this value Default value (applies to enumeration)

18 XML 18 Enterprise Applications CE00465-M XML DOCTYPE Document Type Declarations –Specifies the location of the DTD defining the syntax and structure of elements in the document –Common forms –The root identifies the starting element (root element) of the document –The DTD can be external to the XML document, referenced by a SYSTEM or PUBLIC URL SYSTEM URL refers to a private DTD –Located on the local file system or HTTP server PUBLIC URL refers to a DTD intended for public use

19 XML 19 Enterprise Applications CE00465-M XML DOCTYPE Specifying a PUBLIC DTD –The Formal Public identifier (FPI) has four parts: 1.Connection of DTD to a formal standard 2.Group responsible for the DTD 3.Description and type of document 4.Language used in the DTD –Examples: <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” http://www.w3.org/TR/html4/strict.dtd>

20 XML 20 Enterprise Applications CE00465-M XML Comments The same as HTML comments

21 XML 21 Enterprise Applications CE00465-M Processing Instructions Application-specific instruction to the XML processor – Example 2 Harry Nelson 250 2005-09-28 Computer Science VP

22 XML 22 Enterprise Applications CE00465-M XML Root Element Required for XML-aware applications to recognise beginning and end of document Example 2 Harry Nelson 250 2005-09-28 Computer Science VP

23 XML 23 Enterprise Applications CE00465-M XML Tags Tag names; –Case sensitive –Start with a letter or underscore –After first character, numbers, ‘-’ and ‘.’ are allowed –Cannot contain whitespaces –Avoid use of colon except for indicating namespaces For a well-formed XML document –Every tag must have an end tag ….. –All tags must be nested (tag order can’t be mixed) Tags can also have attributes –Attributes provide metadata for the element –Every attribute value must be enclosed in ”” with no commas between attributes –Same naming convention as elements

24 XML 24 Enterprise Applications CE00465-M Document Entities Entities refer to data item, typically text –General entity references start with & and end with ; –The entity reference is replaced by its true value when parsed –The characters & ’ “ require entity references to avoid conflicts with the XML application (parser) <>& &apos;" Entities are user definable <!DOCTYPE university[ ]> My Faculty is,&myfaculty; Note we’ve included the DTD in the prolog of the above code

25 XML 25 Enterprise Applications CE00465-M Document Entities Internet Explorer displays:

26 XML 26 Enterprise Applications CE00465-M CDATA Sections CDATA (character data) is not parsed Example // C++ comment if ( this->getX() < 5 && value[ 0 ] != 3 ) cerr << this->displayError(); <![CDATA[ // C++ comment if ( this->getX() < 5 && value[ 0 ] != 3 ) cerr displayError(); ]]> C++ How to Program by Deitel & Deitel

27 XML 27 Enterprise Applications CE00465-M CDATA Sections Internet Explorer displays

28 XML 28 Enterprise Applications CE00465-M Extensible Stylesheet Language (XSL) Consists of two parts –XSL Transformation language (XLST) Used to transform an XML document from one form to another –XSL formatting objects Provides an alternative to CSS for formatting and styling an XML document More information –XML: http://www.w3schools.com/xml/default.asp –DTD:http://www.w3schools.com/dtd/default.asp –XSLT:http://www.w3schools.com/xsl/default.asp


Download ppt "XML 1 Enterprise Applications CE00465-M XML. 2 Enterprise Applications CE00465-M XML Overview Extensible Mark-up Language (XML) is a meta-language that."

Similar presentations


Ads by Google