Friday, December 22, 2006

XML Data island @ XML

In an HTML document, you can embed the XML file above with the xml tag. The id attribute of the xml tag defines an ID for the data island, and the src attribute points to the XML file to embed:

The datasrc attribute of the tag binds the HTML table element to the XML data island. The datasrc attribute refers to the id attribute of the data island.
tags cannot be bound to data, so we are using tags. The tag allows the datafld attribute to refer to the XML element to be displayed.


To manipulate an XML document, you need an XML parser. The parser loads the document into your computer's memory. Once the document is loaded, its data can be manipulated using the DOM. The DOM treats the XML document as a tree.

There are some differences between Microsoft's XML parser and the XML parser used in Mozilla browsers.

Microsoft's XML Parser
Microsoft's XML parser is a COM component that comes with Internet Explorer 5 and higher. Once you have installed Internet Explorer, the parser is available to scripts.
Microsoft's XML parser supports all the necessary functions to traverse the node tree, access the nodes and their attribute values, insert and delete nodes, and convert the node tree back to XML.
To create an instance of Microsoft's XML parser, use the following code:

JavaScript:
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");

VBScript:
set xmlDoc=CreateObject("Microsoft.XMLDOM")

ASP:
set xmlDoc=Server.CreateObject("Microsoft.XMLDOM")
The following code fragment loads an existing XML document ("note.xml") into Microsoft's XML parser:
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load("note.xml");
The first line of the script above creates an instance of the XML parser. The second line turns off asynchronized loading, to make sure that the parser will not continue execution of the script before the document is fully loaded. The third line tells the parser to load an XML document called "note.xml".

XML Parser in Mozilla, Firefox, and Opera

Mozilla's XML parser supports all the necessary functions to traverse the node tree, access the nodes and their attribute values, insert and delete nodes, and convert the node tree back to XML.
To create an instance of the XML parser in Mozilla browsers, use the following code:

JavaScript:
var xmlDoc=document.implementation.createDocument("ns","root",null);
The first parameter, ns, defines the namespace used for the XML document. The second parameter, root, is the XML root element in the XML file. The third parameter, null, is always null because it is not implemented yet.
The following code fragment loads an existing XML document ("note.xml") into Mozillas' XML

parser:
var xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.load("note.xml");
The first line of the script above creates an instance of the XML parser. The second line tells the parser to load an XML document called "note.xml".

http://www.w3schools.com/xml/xml_data_island.asp

No comments: