Scripting XML Elements

Internet Explorer provides limited support for scripting XML elements. For example, I can add an onclick event attribute to an XML element named <xlink> (we'll take a look at XLinks later in this book) in an XHTML document (we'll also take a look at XHTML later in this book):

Listing ch07_12.html
 <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet TYPE="text/css" href="ch07_13.css"?> <html>     <head>     </head>     <body>  Want to check out <xlink xml:link = "simple" inline="false"   href="http://www.w3c.org"   onclick="location.href='http://www.w3c.org/default.htm'">W3C</xlink>?  </body> </html> 

I can specify in a stylesheet, ch07_13.css, that <xlink> elements should be displayed in blue and underlined as a hyperlink might appear. I can also specify that the mouse cursor should change to a hand when over this element, just as it would for an HTML hyperlink:

Listing ch07_13.css
 xlink {color: #0000FF; text-decoration: underline; cursor: hand} 

The results appear in Figure 7-9. When the user clicks the <xlink> element, Internet Explorer executes the code in the onClick event attribute. In this case, that navigates the browser to www.w3c.org. As you can see, you can script XML elements in Internet Explorer, adding event attributes such as onclick .

Figure 7-9. Creating a "hyperlink" in an XML document in Internet Explorer.

graphics/07fig09.gif



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net