• One of the most important uses of XML is in e-commerce, • Data (XML file itself)
• where a set of tags can be agreed upon by several companies doing
business together.
• Formatting (XSLT or CSS)
• XML can also be used as the basic format
• to exchange messages between processes in distributed into three different files that can be manipulated
applications, allowing more flexibility in communications.
independently
3 4
1
Structured, Static and Dynamic documents Structured, Static and Dynamic documents
• What is a Structured Document ? • What is a Structured Document ? … contd.
The term Structured Document describes the concept that a document can be
viewed in a number of ways:
Formatting Rendering
• Logical Structure: This refers to the organization as seen by the
author - a book might consist of a preface, a table of contents, some chapter, a
bibliography and an index. The chapters might contain sections, which in turn,
contain paragraphs and graphics, ... Logical Physical Output
Document Document Document
• Physical Structure: This is often the structure as seen by the publisher
- a book might consist of a cover, and pages (which exist as galleys before
they are divided into pages). The pages might be divided into paragraphs
or drawings etc.
5 6
Structured, Static and Dynamic documents Structured, Static and Dynamic documents
• Why do we need structure in documents (electronic) • What is a Static Document?
Portability • Hardcopy document model
Re-usability • No interaction with information
Inter-system operability • No response from document
Ease of storage and retrieval • User takes a passive role
Low distribution costs • Examples of Static Mediums:- Books- Movies- Paintings-
Sculpture- Television
Quick access
Ease of maintenance and updating
• What is a Dynamic Document?
Longevity
• Information can change
Ease of organization and re-organization
• Allows interaction with information
Appearance easily changed
• Produces a response to interaction
• Disadvantages
• User takes an active role
• High start-up costs
• Examples of Dynamic Mediums:- Computer Games - The Internet-
• Huge initial time commitment
7 Interactive Television 8
2
XML on the server XML on the Server – Example (ASP)
Why? Accessing data from XML file using ASP
– processing done on server, only result sent to client – Map the absolute path to the XML file
• don't have worry about browser compatibility issues
• strPath = Server.MapPath( “test.xml" )
• can hide data from user
– can use different stylesheets and xsl for different – test.xml:
browsers <?xml version="1.0"?>
– systems can provide better performance and <test>
<child>
maintainability for data-driven web sites by generating <text>Text of first child element</text>
and caching frequently accessed pages ahead of time </child>
on the server. <child>
<text>Text of second child element</text>
Possible Negative: </child>
</test>
– places higher load on server
9 10
Accessing data from XML file using ASP (cont.) Accessing data from XML file using ASP (cont.)
– Saving nodes from XML document to variables:
Set xmlRoot = xmlFile.DocumentElement
– Create a DOM object for the XML file to be loaded Set xmlNodes = xmlFile.DocumentElement.ChildNodes
into:
Set xmlFile = Server.CreateObject( "Microsoft.XMLDOM" ) – Displaying content of nodes:
<%
xmlFile.Async = False
For Each xmlItem In xmlNodes
strText = xmlItem.text
%>
– Load the XML file into the variable <li>
<% =strText %>
xmlFile.Load( strPath ) </li>
<%
Next
%>
11 12
3
Adding content to the XML file: Adding an attribute to the element:
– Create a new node:
– Create a new node: Set xmlNode = xmlFile.CreateElement(“child”)
Set xmlNode = xmlFile.CreateElement(“child”) – Creating an empty element
– Creating an empty element Call xmlNode.SetAttribute( “attName", “attValue” )
– Creates an attribute called attName with a value of attValue
xmlNode.Text = “Text of third child element”
xmlNode.Text = “Text of third child element”
– Adds some text into the ‘child’ node – Adds some text into the ‘child’ node
Call xmlRoot.AppendChild(xmlNode) Call xmlRoot.AppendChild(xmlNode)
– Appends the new node to the root element stored in – Appends the new node to the root element stored in xmlRoot
xmlRoot – See:
http://www.devguru.com/technologies/xmldom/quickref/node_appendC
– Save the file: hild.html for another example using appendChild()
13 14
4
default.asp
Get absolute path to xml file (needed by
msxml when parsing the file)
– Server.MapPath("forums.xml")
Create a DOM object:
– Server.CreateObject("Microsoft.XMLDOM")
Example:
Dim strPath, xmlFile
strPath = Server.MapPath("forums.xml")
Set xmlFile =
Server.CreateObject("Microsoft.XMLDOM")
xmlFile.Async = False
17 18
5
default.asp
Clicking the “Forum 1 Name” link will open
forum1.xml in the browser
– forum1.xml has a link to an xsl (formatting.xsl)
that will format the xml for display
21 22
forum1.xml addPost.asp
23 24
6
addForum.asp addForum.asp
Preforms two tasks:
– Displays the form that gets the new forum’s
information
– Provides the script for creating the forum
25 26
Adding elements and attributes: Saving the new xml file on the server:
– Create a new element node – Call xmlFile.Save(strPath)
• Set xmlNode =
xmlFile.CreateElement(“name”)
– “name” is the name given to the new element
• xmlNode.text = “element text”
– Append the new element node to root
element
• Call xmlRoot.AppendChild(xmlNode)
– Adding an attribute to root node:
• xmlRoot.SetAttribute(“attributeName”,
“attributeContent”) 27 28
7
XML & PHP XML & ASP
For intro on accessing xml with php using Accessing XML data using ASP:
– Part 1:
DOM, see: http://www.4guysfromrolla.com/webtech/101200-1.shtml
http://www.w3schools.com/dom/dom_examples.asp DevGuru:
XML manipulation using PHP: – selectNodes() method example:
http://www.w3schools.com/dom/dom_examples.asp http://www.devguru.com/technologies/xmldom/quickref/node_selectNodes.html
– selectSingleNode() method example:
http://www.php.net/manual/en/intro.dom.php http://www.devguru.com/technologies/xmldom/quickref/node_selectSingleNode.html
ASP 101:
– Saving HTML form data to XML using ASP:
http://www.asp101.com/articles/michael/htmlxml/
– Appending to XML with ASP:
http://www.asp101.com/articles/michael/htmlxml/
29 30