Skip to main content

Posts

Showing posts from October, 2009

XML and CSS

Below is a fraction of the XML file. The second line links the XML file to the CSS file: Empire Burlesque Bob Dylan USA Columbia 10.90 1985 Hide your heart Bonnie Tyler UK CBS Records 9.90 1988 . . . ------------------- css file : CATALOG { background-color: #ffffff; width: 100%; } CD { display: block; margin-bottom: 30pt; margin-left: 0; } TITLE { color: #FF0000; font-size: 20pt; } ARTIST { color: #0000FF; font-size: 20pt; } COUNTRY,PRICE,YEAR,COMPANY { display: block; color: #000000; margin-left: 20pt; }

XML Files

Viewing XML Files - < note > < to > Tove to > < from > Jani from > < heading > Reminder heading > < body > Don't forget me this weekend! body > note > Look at this XML file: note.xml The XML document will be displayed with color-coded root and child elements. A plus (+) or minus sign (-) to the left of the elements can be clicked to expand or collapse the element structure. To view the raw XML source (without the + and - signs), select "View Page Source" or "View Source" from the browser menu.

XML in real life.

Example: XML News XMLNews is a specification for exchanging news and other information. Using such a standard makes it easier for both news producers and news consumers to produce, receive, and archive any kind of news information across different hardware, software, and programming languages. An example XMLNews document: Colombia Earthquake 143 Dead in Colombia Earthquake By Jared Kotler, Associated Press Writer Bogota, Colombia Monday January 25 1999 7:28 ET Example: XML Weather Service An example of an XML national weather service from NOAA (National Oceanic and Atmospheric Administration):
XML Elements vs. Attributes Take a look at these examples: Anna Smith female Anna Smith In the first example sex is an attribute. In the last, sex is an element. Both examples provide the same information. There are no rules about when to use attributes and when to use elements. Attributes are handy in HTML. In XML my advice is to avoid them. Use elements instead.

XML - 2

(XML Tree) Example: The image above represents one book in the XML below: Everyday Italian Giada De Laurentiis 2005 30.00 Harry Potter J K. Rowling 2005 29.99 Learning XML Erik T. Ray 2003 39.95 The root element in the example is . All elements in the document are contained within . The element has 4 children: , <>, , . ---------------------------------------------------------------- XML Tags are Case Sensitive Entity References Some characters have a special meaning in XML. If you place a character like "<" inside an XML element, it will generate an error because the parser interprets it as the start of a new element. This will generate an XML error: if salary <> To avoid this error, replace the "<" character with an entity reference : if salary < 1000 then There are 5 predefined entity references in XML: < <

Introduction to XML

What is XML? XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to carry data, not to display data XML tags are not predefined. You must define your own tags XML is designed to be self-descriptive XML is a W3C Recommendation The Difference Between XML and HTML XML is not a replacement for HTML. XML and HTML were designed with different goals: XML was designed to transport and store data, with focus on what data is. HTML was designed to display data, with focus on how data looks. HTML is about displaying information, while XML is about carrying information. XML language has no predefined tags. The tags used in HTML (and the structure of HTML) are predefined. HTML documents can only use tags defined in the HTML standard (like , , etc.). XML allows the author to define his own tags and his own document structure. XML Separates Data from HTML If you need to display dynamic data in your HTML document, it will take a lot of work to edi