Extensible markup language
XML (Extensible Markup Language) adalah bahasa markup untuk keperluan umum yang disarankan oleh W3C untuk membuat dokumen markup keperluan pertukaran data antar sistem yang beraneka ragam. XML merupakan kelanjutan dari HTML (HyperText Markup Language) yang merupakan bahasa standar untuk melacak Internet.
Mengenal XML
XML didesain untuk mempu menyimpan data secara ringkas dan mudah diatur. Kata kunci utama XML adalah data (jamak dari datum) yang jika diolah bisa memberikan informasi
XML menyediakan suatu cara terstandarisasi namun bisa dimodifikasi untuk menggambarkan isi dari dokumen. Dengan sendirinya, XML dapat digunakan untuk menggambarkan sembarang view database, tetapi dengan suatu cara yang standar.
Tipe XML
XML, merupakan standar format dari struktur berkas (file).
XSL, merupakan standar untuk memodifikasi data yang diimpor atau diekspor.
XSD, merupakan standar yang mendefinisikan struktur database dalam XML.
Keunggulan XML
Keunggulan XML bisa diringkas sebagai berikut :
Pintar (Intelligence). XML dapat menangani berbagai tingkat (level) kompleksitas.
Dapat beradaptasi. Dapat mengadaptasi untuk membuat bahasa sendiri. Seperti Microsoft membuaat bahasa MSXML atau Macromedia mengembangkan MXML.
Mudah pemeliharaannya.
Sederhana. XML lebih sederhana.
Mudah dipindah-pindahkan (Portability). XML mempunyai kemudahan perpindahan (portabilitas) yang lebih bagus.
Contoh dokumen XML sederhana
version="1.0" encoding="UTF-8"?> > >
|
Aturan Syntax XML
The syntax rules of XML are very simple and logical. The rules are easy to learn, and easy to use.
All XML Elements Must Have a Closing Tag
In HTML, elements do not have to have a closing tag:
This is a paragraph
This is another paragraph |
|
In XML, it is illegal to omit the closing tag. All elements must have a closing tag:
This is a paragraph This is another paragraph |
Note: You might have noticed from the previous example that the XML declaration did not have a closing tag. This is not an error. The declaration is not a part of the XML document itself, and it has no closing tag.
XML Tags are Case Sensitive
XML tags are case sensitive. The tag
Opening and closing tags must be written with the same case:
|
Note: "Opening and closing tags" are often referred to as "Start and end tags". Use whatever you prefer. It is exactly the same thing.
XML Elements Must be Properly Nested
In HTML, you might see improperly nested elements:
This text is bold and italic |
|
In XML, all elements must be properly nested within each other:
This text is bold and italic |
|
In the example above, "Properly nested" simply means that since the element is opened inside the element, it must be closed inside the element.
XML Documents Must Have a Root Element
XML documents must contain one element that is the parent of all other elements. This element is called the root element.
|
|
XML Attribute Values Must be Quoted
XML elements can have attributes in name/value pairs just like in HTML.
In XML, the attribute values must always be quoted.
Study the two XML documents below. The first one is incorrect, the second is correct:
|
|
| |
| ||
|
|
|
|
The error in the first document is that the date attribute in the note element is not quoted.
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:
|
To avoid this error, replace the "<" character with an entity reference:
|
There are 5 predefined entity references in XML:
< | < | less than |
> | > | greater than |
& | & | ampersand |
' | ' | apostrophe |
" | " | quotation mark |
Note: Only the characters "<" and "&" are strictly illegal in XML. The greater than character is legal, but it is a good habit to replace it.
Comments in XML
The syntax for writing comments in XML is similar to that of HTML.
White-space is Preserved in XML
HTML truncates multiple white-space characters to one single white-space:
HTML: | Hello Tove |
Output: | Hello Tove |
With XML, the white-space in a document is not truncated.
XML Stores New Line as LF
In Windows applications, a new line is normally stored as a pair of characters: carriage return (CR) and line feed (LF). In Unix applications, a new line is normally stored as an LF character. Macintosh applications also use an LF to store a new line.
XML stores a new line as LF.
What is an XML Element?
An XML element is everything from (including) the element's start tag to (including) the element's end tag.
An element can contain:
other elements
text
attributes
or a mix of all of the above...
|
|
In the example above,
<to>Tove</to>
<from>Jani</from>
<body>Don't forget me this weekend!</body>
</note></span><span style="font-size:12.0pt;line-height:200%; font-family:"Arial","sans-serif";mso-ansi-language:EN-US"></span></p> </td> </tr> </tbody></table> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"; mso-ansi-language:EN-US"> </span></p> <table class="MsoNormalTable" style="width:100.0%;mso-cellspacing:0in;mso-yfti-tbllook:1184;mso-padding-alt: 0in 0in 0in 0in" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes"> <td style="padding:0in 0in 0in 0in">
</td> </tr> </tbody></table> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">Let's imagine that we created an application that extracted the <to>, <from>, and <body> elements from the XML document to produce this output:</span></p> <table class="MsoNormalTable" style="width:100.0%;mso-cellspacing:0in;background:yellow;mso-yfti-tbllook: 1184" border="1" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes"> <td style="padding:.75pt .75pt .75pt .75pt"> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"; mso-bidi-font-weight:bold" lang="IN">MESSAGE</span><span style="font-size:12.0pt; line-height:200%;font-family:"Arial","sans-serif"" lang="IN"> </span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"; mso-bidi-font-weight:bold" lang="IN">To:</span><span style="font-size:12.0pt; line-height:200%;font-family:"Arial","sans-serif"" lang="IN"> Tove
<span style="mso-bidi-font-weight:bold">From:</span> Jani</span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">Don't forget me this weekend!</span></p> </td> </tr> </tbody></table> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">Imagine that the author of the XML document added some extra information to it:</span></p> <table class="MsoNormalTable" style="width:100.0%;mso-cellspacing:0in;mso-yfti-tbllook:1184;mso-padding-alt: 0in 0in 0in 0in" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes"> <td style="padding:0in 0in 0in 0in"> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"><note>
<date>2008-01-10</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note></span></p> </td> </tr> </tbody></table> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">Should the application break or crash?</span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">No. The application should still be able to find the <to>, <from>, and <body> elements in the XML document and produce the same output.</span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">One of the beauties of XML, is that it can be extended without breaking applications.</span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"> </span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">XML <span class="colorh1">Attributes</span></span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"> </span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">XML elements can have attributes, just like HTML.</span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">Attributes provide additional information about an element.</span></p> <div class="MsoNoSpacing" style="text-align:center;line-height:200%" align="center"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"> <hr align="center" size="2" width="100%"> </span></div> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">XML Attributes</span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">In HTML, attributes provide additional information about elements:</span></p> <table class="MsoNormalTable" style="width:100.0%;mso-cellspacing:0in;mso-yfti-tbllook:1184;mso-padding-alt: 0in 0in 0in 0in" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes"> <td style="padding:0in 0in 0in 0in"> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"><img src="computer.gif">
<a href="demo.asp"></span></p> </td> </tr> </tbody></table> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">Attributes often provide information that is not a part of the data. In the example below, the file type is irrelevant to the data, but can be important to the software that wants to manipulate the element:</span></p> <table class="MsoNormalTable" style="width:100.0%;mso-cellspacing:0in;mso-yfti-tbllook:1184;mso-padding-alt: 0in 0in 0in 0in" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes"> <td style="padding:0in 0in 0in 0in"> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"><file type="gif">computer.gif</file></span></p> </td> </tr> </tbody></table> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"> </span></p> <div class="MsoNoSpacing" style="text-align:center;line-height:200%" align="center"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"> <hr align="center" size="2" width="100%"> </span></div> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">XML Attributes Must be Quoted</span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">Attribute values must always be quoted. Either single or double quotes can be used. For a person's sex, the person element can be written like this:</span></p> <table class="MsoNormalTable" style="width:100.0%;mso-cellspacing:0in;mso-yfti-tbllook:1184;mso-padding-alt: 0in 0in 0in 0in" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes"> <td style="padding:0in 0in 0in 0in"> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"><person sex="female"></span></p> </td> </tr> </tbody></table> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">or like this:</span></p> <table class="MsoNormalTable" style="width:100.0%;mso-cellspacing:0in;mso-yfti-tbllook:1184;mso-padding-alt: 0in 0in 0in 0in" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes"> <td style="padding:0in 0in 0in 0in"> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"><person sex='female'></span></p> </td> </tr> </tbody></table> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">If the attribute value itself contains double quotes you can use single quotes, like in this example:</span></p> <table class="MsoNormalTable" style="width:100.0%;mso-cellspacing:0in;mso-yfti-tbllook:1184;mso-padding-alt: 0in 0in 0in 0in" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes"> <td style="padding:0in 0in 0in 0in"> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"><gangster name='George "Shotgun" Ziegler'></span></p> </td> </tr> </tbody></table> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">or you can use character entities:</span></p> <table class="MsoNormalTable" style="width:100.0%;mso-cellspacing:0in;mso-yfti-tbllook:1184;mso-padding-alt: 0in 0in 0in 0in" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes"> <td style="padding:0in 0in 0in 0in"> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"><gangster name="George "Shotgun" Ziegler"></span></p> </td> </tr> </tbody></table> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"> </span></p> <div class="MsoNoSpacing" style="text-align:center;line-height:200%" align="center"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"> <hr align="center" size="2" width="100%"> </span></div> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">XML Elements vs. Attributes</span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">Take a look at these examples:</span></p> <table class="MsoNormalTable" style="width:100.0%;mso-cellspacing:0in;mso-yfti-tbllook:1184;mso-padding-alt: 0in 0in 0in 0in" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes"> <td style="padding:0in 0in 0in 0in"> <p class="MsoNoSpacing" style="line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"><person sex="female">
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person></span></p> </td> </tr> </tbody></table> <p class="MsoNoSpacing" style="line-height:200%"><span style="font-size: 12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"> </span></p> <table class="MsoNormalTable" style="width:100.0%;mso-cellspacing:0in;mso-yfti-tbllook:1184;mso-padding-alt: 0in 0in 0in 0in" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes"> <td style="padding:0in 0in 0in 0in"> <p class="MsoNoSpacing" style="line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"><person>
<sex>female</sex>
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person></span></p> </td> </tr> </tbody></table> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">In the first example sex is an attribute. In the last, sex is an element. Both examples provide the same information.</span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">There are no rules about when to use attributes or when to use elements. Attributes are handy in HTML. In XML my advice is to avoid them. Use elements instead.</span></p> <div class="MsoNoSpacing" style="text-align:center;line-height:200%" align="center"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"> <hr align="center" size="2" width="100%"> </span></div> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">My Favorite Way</span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">The following three XML documents contain exactly the same information:</span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">A date attribute is used in the first example:</span></p> <table class="MsoNormalTable" style="width:100.0%;mso-cellspacing:0in;mso-yfti-tbllook:1184;mso-padding-alt: 0in 0in 0in 0in" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes"> <td style="padding:0in 0in 0in 0in"> <p class="MsoNoSpacing" style="line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"><note date="10/01/2008">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note></span></p> </td> </tr> </tbody></table> <p class="MsoNoSpacing" style="line-height:200%"><span style="font-size: 12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">A date element is used in the second example:</span></p> <table class="MsoNormalTable" style="width:100.0%;mso-cellspacing:0in;mso-yfti-tbllook:1184;mso-padding-alt: 0in 0in 0in 0in" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes"> <td style="padding:0in 0in 0in 0in"> <p class="MsoNoSpacing" style="line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"><note>
<date>10/01/2008</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note></span></p> </td> </tr> </tbody></table> <p class="MsoNoSpacing" style="line-height:200%"><span style="font-size: 12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">An expanded date element is used in the third: (THIS IS MY FAVORITE):</span></p> <table class="MsoNormalTable" style="width:100.0%;mso-cellspacing:0in;mso-yfti-tbllook:1184;mso-padding-alt: 0in 0in 0in 0in" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes"> <td style="padding:0in 0in 0in 0in"> <p class="MsoNoSpacing" style="line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"><note>
<date>
<day>10</day>
<month>01</month>
<year>2008</year>
</date>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note></span></p> </td> </tr> </tbody></table> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"> </span></p> <div class="MsoNoSpacing" style="text-align:center;line-height:200%" align="center"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"> <hr align="center" size="2" width="100%"> </span></div> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">Avoid XML Attributes?</span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">Some of the problems with using attributes are:</span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">attributes cannot contain multiple values (elements can)</span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">attributes cannot contain tree structures (elements can)</span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">attributes are not easily expandable (for future changes)</span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">Attributes are difficult to read and maintain. Use elements for data. Use attributes for information that is not relevant to the data.</span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">Don't end up like this:</span></p> <table class="MsoNormalTable" style="width:100.0%;mso-cellspacing:0in;mso-yfti-tbllook:1184;mso-padding-alt: 0in 0in 0in 0in" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes"> <td style="padding:0in 0in 0in 0in"> <p class="MsoNoSpacing" style="line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"><note day="10" month="01" year="2008"
to="Tove" from="Jani" heading="Reminder"
body="Don't forget me this weekend!">
</note></span></p> </td> </tr> </tbody></table> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"> </span></p> <div class="MsoNoSpacing" style="text-align:center;line-height:200%" align="center"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"> <hr align="center" size="2" width="100%"> </span></div> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">XML Attributes for Metadata</span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">Sometimes ID references are assigned to elements. These IDs can be used to identify XML elements in much the same way as the id attribute in HTML. This example demonstrates this:</span></p> <table class="MsoNormalTable" style="width:100.0%;mso-cellspacing:0in;mso-yfti-tbllook:1184;mso-padding-alt: 0in 0in 0in 0in" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes"> <td style="padding:0in 0in 0in 0in"> <p class="MsoNoSpacing" style="line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"><messages>
<note id="501">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<note id="502">
<to>Jani</to>
<from>Tove</from>
<heading>Re: Reminder</heading>
<body>I will not</body>
</note>
</messages></span></p> </td> </tr> </tbody></table> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">The id attributes above are for identifying the different notes. It is not a part of the note itself.</span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN">What I'm trying to say here is that metadata (data about data) should be stored as attributes, and the data itself should be stored as elements.</span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"" lang="IN"> </span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"; mso-ansi-language:EN-US"> </span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"; mso-ansi-language:EN-US"> </span></p> <p class="MsoNoSpacing" style="text-align:justify;line-height:200%"><span style="font-size:12.0pt;line-height:200%;font-family:"Arial","sans-serif"; mso-ansi-language:EN-US"> </span></p>
No comments:
Post a Comment