Review of XML IST 421 Spring 2004 Lecture

























- Slides: 25
Review of XML IST 421 Spring 2004 Lecture 5
XML o e. Xtensible Markup Language o Used for digital representation of documents n Store, process, search, transmit, display and print documents o www. w 3 c. org/xml - current information about XML
XML o Basic building block is the element, defined by tags o Root element contains all of the other elements o Attributes describe properties of elements o XML uses delimiters to differentiate character data n Less than < and greater than > called a tag
XML Elements o Name the contents of the element. o Typically in pairs with a start and end tag. o Some elements take attributes. o The structure describes the relationship between the elements. Example: <order_no>101</order_no>
XML Elements o May start with a letter or an underscore o May consist of: Letters n Digits n Underscore character n Dot n Hyphen o Cannot start with the string “xml” n
XML Elements o XML names are case sensitive unlike HTML tags which are not o Must have one root element – Similar to the <HTML>; </HTML> in html type of document – Programmer defines a root name o First line must be xml declaration – <? xml version=“ 1. 0”? > (Note: ? Means information is passed)
XML Comments o <!-- ………--> o Any text desired can be placed within the <!-- -- > Example: <!-- Updated Apr 3 -->
XML Processing Instructions o Enables the passing of information to another application o Format: <? … o Specifies version. ? > Example: <? xml version “ 1. 0”? >
Let’s Practice 1. 2. 3. 4. 5. 6. 7. 8. Open Microsoft Notes (not XML notes!) Declare the XML version as “ 1. 0” Create a Root Element, called class_listing Note that every element must have both a beginning and ending tag Save as: class_listing. xml Add some other elements! Create data within each element! Test this in the browser.
Review the Practice o XML data is hierarchical o Elements contained within other elements are called children o Elements that contain children are called parent elements – nesting o Each XML document contains a root element o Element names describe the data
Components of XML Documents o XML Declaration n First line of document n Declaration tag begins with: <? xml version=“ 1. 0” encoding=“UTF-8” standalone=“no”? > n May contain 3 attributes: p version=“ 1. 0” p encoding=“UTF-8” (default if not given) p standalone=“yes” or standalone=“no” (default) UTF-8 = 8 -bit Unicode character-encoding scheme. Others are UTF-16, UTF-32, and ISO-10646 -UCS-2.
Attributes o Attributes may be attached to elements o Attributes have: n n Names Values o Name is separated from value by “=“ sign o Value must have “ “ around it
Attributes o Creates additional information o It is often information about the ELEMENT content o Nesting an ELEMENT within others may accomplish the same purpose
Let’s Practice o Add attribute to define categorize of student status o <student status=“sr”> o Add this attribute to all students o Remember to save with. xml extension.
XML Entities o Entities are used as placeholders for content o Two types of entities: n n General Parameter
XML General Entities o Placeholders for any information contained in the root element o Three types: n n n Character – used in place of special characters Content – used to mark the place of a common block of content that you type often Unparsed – used for binary or nontext data like images or video clips
Character Entities o Some tag delimiter characters have special meaning in XML <? xml version=“ 1. 0”? > <equation> 50 < 100 </equation> Cause a syntax error
Character Entities o Solve problem by using character entities: > < “ ‘ > < " '
Content Entities o Used to mark the place of a common block of content that you type often or that may change n n n Internal entities – defined as part of the DTD within the XML document Example: <!DOCTYPE class_listing [ <!ENTITY campus "Harrisburg"> ]> <class_campus>Penn State &campus; </class_campus> External entities – information saved in an external file with a. xml extension
Unparsed Entities o Used for binary or nontext data like images or video clips <!ENTITY picture SYSTEM “sunset. gif” NDATA GIF> NDATA = notation data The unparsed entity declaration tells the processing system not to parse the data but rather to pass it through as is.
Well-Formed XML o Document that adheres to XML syntax rules – well formed o Rules: Must contain only one root element n All elements must have a start and end tag n Elements must be nested properly and cannot overlap <book><chapter> …. </book></chapter> n
Well-Formed XML o Rules (cont. ) n All attributes must have a value and must be enclosed in quotes <student status=“sr”> n Attributes must be placed in the start tag of an element and may appear only once Element names are case-sensitive <STUDENT> vs. </student> n
Well-Formed XML o Rules (cont. ) n n n Certain markup characters are reserved such as < and >. Must use a character entity instead Element names may start with letters or an underscore; names may contain only letters, numbers, hyphens, periods, and underscore Element names may not start with xml
XML Parser o XML Parser is a program that checks an XML document to ensure it follows the rules and is well formed. n n n Nonvalidating parser – looks for syntax errors according to the language rules Validating parser – checks your document against a DTD or schema Like compilers, one error may cause many messages
Homework o Create an XML document for the following: Camping Trip Gear List The following is a list of items that are essential on any camping trip: Flashlight Sleeping bag Bug spray Hatchet Shovel Bucket Hiking boots Pocket knife Compass Lantern Tent Ground cloth