nikhil joshi
Posts tagged Theory
XML Theory…
Oct 2nd
Advantages of XML
-
Simplifies Data Sharing: XML data is stored in plain text format. This provides a software- and hardware-independent way of storing data.
-
Simplifies Data Transport: With XML, data can easily be exchanged between incompatible systems.
-
Since XML is independent of hardware, software and application, XML can make your data more available and useful. Different applications can access your data, not only in HTML pages, but also from XML data sources.
-
Here are some examples:
-
XHTML the latest version of HTML
-
WSDL for describing available web services
-
WAP and WML as markup languages for handheld devices
-
RSS languages for news feeds
-
RDF and OWL for describing resources and ontology
-
SMIL for describing multimedia for the web
-
-
XML Elements are Extensible: XML elements can be extended to carry more information.
XML Syntax rules:
-
XML Documents Must Have a Root Element
-
All XML Elements Must Have a Closing Tag
-
XML Tags are Case Sensitive
-
XML Elements Must be Properly Nested
-
XML Attribute Values Must be Quoted
-
Entity References
< < less than
> > greater than
& & ampersand
' ‘ apostrophe
" " quotation mark
XML attributes:
Attributes provide additional information about elements. Disadvantages of attributes:
-
attributes cannot contain multiple values (elements can)
-
attributes cannot contain tree structures (elements can)
-
attributes are not easily expandable (for future changes)
-
Attributes are difficult to read and maintain.
moral of attribute story – use elements instated of attributes.
XML Namespaces and name conflicts
Name conflicts in XML can easily be avoided using a name prefix.
<h:table>
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
XML Namespaces provide a method to avoid element name conflicts.
-
xmlns attribute for element.
When using prefixes in XML, a so-called namespace for the prefix must be defined.
The namespace is defined by the xmlns attribute in the start tag of an element.
The namespace declaration has the following syntax. xmlns:prefix="URI"
<root>
<h:table xmlns:h="http://www.w3.org/TR/html4/">
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table xmlns:f="http://www.w3schools.com/furniture">
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root> -
Default Namespaces
Defining a default namespace for an element saves us from using prefixes in all the child elements.
<table xmlns="http://www.w3.org/TR/html4/">
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>
CDATA
XML parsers normally parse all the text in an XML document. The term CDATA is used about text data that should not be parsed by the XML parser.
Characters like "<" and "&" are illegal in XML elements.
"<" will generate an error because the parser interprets it as the start of a new element.
"&" will generate an error because the parser interprets it as the start of an character entity.
Some text, like JavaScript code, contains a lot of "<" or "&" characters. To avoid errors script code can be defined as CDATA.
Everything inside a CDATA section is ignored by the parser.
A CDATA section starts with "":
<script>
<![CDATA[
function matchwo(a,b)
{
if (a < b && a < 0) then
{
return 1;
}
else
{
return 0;
}
}
]]>
</script>
Recent Comments