Java Reference
In-Depth Information
your own elements to describe the data enclosed in the element. The ability to defi ne the structure and
elements used in an XML document is what makes XML a self-describing language. That is, the ele-
ments describe the data they contain, and the structure describes how data are related to each other.
Another method in which XML has become useful is in retrieving data from remote servers. Probably
the most widely known applications of this method are the RSS and Atom formats for web syndication.
These XML documents, and others like them, contain information readily available to anyone. Web
sites or programs can connect to the remote server, download a copy of the XML document, and use the
information however needed.
A third and extremely helpful application of XML is the ability to transfer data between incompatible
systems. An XML document is a plain text document; therefore, all operating systems can read and
write to XML fi les. The only major requirement is an application that understands the XML language
and the document structure. For example, Microsoft recently released details on Microsoft Offi ce Open
XML, the fi le format used in Microsoft Offi ce 2007. The fi les themselves are actually Zip fi les. However,
any program written to read the XML fi les contained in the Zip fi le can display the data with no prob-
lem; it doesn't matter whether they were written under Windows, Mac OS X, any fl avor of Linux, or any
other operating system.
Manipulating XML with JavaScript
As previously mentioned, you use the DOM to load, read, and manipulate XML data; so you learned
most of what you need to manipulate XML within the web browser from the previous sections in the
chapter.
The fi rst task is to read the XML document. This is where most cross-browser problems are located
because IE, you guessed it, doesn't follow the DOM standard, whereas Firefox, Safari, Chrome, and
Opera do. The good news is that once the XML document is loaded, the differences between the
browsers are smaller, although Microsoft has added a lot of useful (but nonstandard) extensions to its
implementation.
Retrieving an XML File in IE
Internet Explorer relies upon the ActiveXObject()object and the MSXML library to fetch and open
XML documents. A variety of ActiveX objects are available for scripting; to create an ActiveX object,
simply call the ActiveXObject() constructor and pass a string containing the version of the ActiveX
object you wish to create.
var xmlDoc = new ActiveXObject(“Microsoft.XMLDOM”);
xmlDoc.load(“myfile.xml”);
This code creates an XML DOM object that enables you to load and manipulate XML documents by
using the version string “Microsoft.XMLDOM”. When the XML DOM object is created, load an XML
document by using the load() method. This code loads a fi ctitious fi le called myfile.xml.
There are multiple versions of the Microsoft MSXML library, with each newer version offering more
features and better performance than the one before. However, the user's computer must have these
Search WWH ::




Custom Search