Unit 8 XML Documents
Key Concepts XML fundamentals XML document format Document declaration XML elements and attributes Parsing Characters and white space Reserved characters CDATA XML namespaces
XML Fundamentals Stored as text files. Can be created with any text editor. Hierarchical data storage format. Must contain at least one (root) element. File names end in.xml extension by default, but vary with use.
Sample XML Document Welcome to XML! 8
Key Points Elements are enclosed in angle brackets <>. The root element is the first element opened and last element closed. Inner elements in the hierarchy are called child elements.
Common Programming Errors Attempting to create more than one root element. Not adhering to case on element tags. Improper nesting.
Improper Nesting Hello World
XML Parsing
Parsing Failure
Characters Supports ASCII and Unicode characters Markup text is enclosed in angle brackets Character data is inserted between tags White space characters include spaces, line feeds, and carriage returns.
Reserved Characters Reserved for use by XML –Ampersand (&) –Left angle bracket (<) –Right angle bracket (>) –Apostrophe (') –Double quote (") Built-in entities –Ampersand (&) Built-in entities –Ampersand (&) –Left angle bracket (<) –Right angle bracket (>) –Apostrophe (') –Double quote (")
Book Sample = Deitel&s XML Primer Paul 13 Deitel Welcome 18 Easy XML 19 XML Elements? 20 Entities
Book Sample (cont'd)
CDATA Example // C++ comment 10 if ( this->getX() < 5 && value[ 0 ] != 3 ) 11 cerr << this->displayError(); <![CDATA[ // C++ comment 18 if ( this->getX() < 5 && value[ 0 ] != 3 ) 19 cerr displayError(); 20 ]]> C++ How to Program by Deitel & Deitel 24
CDATA Example (cont'd)
Namespaces <directory xmlns:text = "urn:deitel:textInfo" 7 xmlns:image = "urn:deitel:imageInfo"> A book list A funny picture
Default Namespaces <directory xmlns = "urn:deitel:textInfo" 7 xmlns:image = "urn:deitel:imageInfo"> A book list A funny picture