http://w3schools.com/xml/default.asp
http://www.php.net/manual/en/ref.xml.php
XML is not a replacement for
HTML. It's a language specification to describe the information in
HTML documents, whereas
HTMLonly presents information. It's used in conjunction with
Java to create small applications in mobile phones, and also to organize and transmit information (
AJAX). The
XML DOM is very similar to the
HTML DOM in
Javascript, but its structure is not based on how a web page should be formed, only information. Here is an example of a document:
<?xml version="1.0" encoding="ISO-5589-1"?> <document> <tag /> </document>
Select what you want to copy and in doing so you will keep the formatting when pasting it. |
It looks like a
HTML document, but it has an odd
DOC-TYPE and unrecognizable tags. Because of this, browsers cannot read it on its own. You have to design your own back-end in order to parse the
XML. There are a couple of rules to designing a
XML document, which you may be familiar with if you ever worked with
XHTML.
All elements must be within a root element.
The root element would be the
instance of the document, because it will be the first node you access. It can also be referred to as an
entry-point, etc., but it can be anything you want.
All tags must be enclosed.
Just like
XHTML,
XML isn't very forgiving when it comes to tags. If you don't close nested tags or a single, empty tag, it will throw an error. That means if you've worked with just
HTML thus far, you better get used to it.
Now that you know how to structure an
XML document, you may be wondering about how it is read by the browser. There are several language specifications for
XML that directly support it, but you can also use server-side languages like
PHP,
ASP, and
Javascript's HTML DOM (client-side). To style the document, you can use
CSS or
XLST. Using
CSS, you can just import the file.
<?xml-stylesheet type="text/css" href="style.css"?>
Select what you want to copy and in doing so you will keep the formatting when pasting it. |
Remind you of anything?
XLST, however, works with
XPath.
XPath uses regular expressions to search and match nodes and then styled using
XLST functions. Since I have no actual experience with them, I won't explain them here. As for parsing the documents, you can read a short article I wrote about using the built-in
DOM module here:
http://www.coderprofile.com/coding-article/92/php-xml-html-dom-basics.
PHP.net also explains the built-in
XML parser module and
SimpleXML library. This all being in
PHP. However, you may be wondering how you can use
Javascript. You may not realize it, but you use the
HTML DOM all the time when you are writing scripts (ie,
document.write,
document.
getElementById(element)). I won't explain the
OOP mechanics of the language here, you can look up
C++ or
Java if you want to know more about it. But these
objects refer to the elements of the document in the
DOM.
Using
AJAX, you can load an
XML document and then parse it.