18.04.2016 Views

Professional JavaScript For Web Developers

javascript for learners.

javascript for learners.

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

XML in <strong>JavaScript</strong><br />

var oProcessor = new XSLTProcessor()<br />

oProcessor.importStylesheet(oXslDom);<br />

oProcessor.setParameter(null, “message”, “Hello World!”);<br />

var oResultDom = oProcessor.transformToDocument(oXmlDom);<br />

Two other methods are related to parameters, getParameter() and removeParameter(), which are<br />

used to get the current value of a parameter and remove the parameter value, respectively. Each method<br />

takes the namespace URI (once again, typically null) and the local name of the parameter:<br />

var oProcessor = new XSLTProcessor()<br />

oProcessor.importStylesheet(oXslDom);<br />

oProcessor.setParameter(null, “message”, “Hello World! “);<br />

alert(oProcessor.getParameter(null, “message”);<br />

oProcessor.removeParameter(null, “message”);<br />

//outputs “Hello World!”<br />

var oResultDom = oProcessor.transformToDocument(oXmlDom);<br />

These methods aren’t used often and are provided mostly for convenience.<br />

Summary<br />

This chapter introduced you to the client-side XML capabilities of Internet Explorer and Mozilla. The<br />

first topic covered was the use of an XML DOM model on the client side using the MSXML library in IE<br />

and a native, DOM-compliant interface in Mozilla. You learned the differences between the two models,<br />

as well as a way to bridge that gap to make your code more straightforward.<br />

Next, you learned about each browser’s support for XPath, a language designed to locate specific parts<br />

of an XML document. This section included discussion on the different implementations in IE and<br />

Mozilla. You learned that IE chose a non-standard API, whereas Mozilla chose to follow the DOM Level<br />

3 XPath specification. Again, methods of creating a standard cross-browser approach were discussed.<br />

The last topic discussed was the concept of <strong>JavaScript</strong> XML manipulation and transformation using<br />

XSLT. You learned about the two ways to accomplish XSLT transformations using <strong>JavaScript</strong> in IE,<br />

through the transformNode() method and the XSLProcessor object. You also learned about Mozilla’s<br />

XSLTProcessor object and how it compares to IE’s implementation. Using XSLTProcessor, you<br />

learned how to create a transformNode() method for use in Mozilla.<br />

Remember, the material covered in this chapter only works in Internet Explorer and Mozilla because<br />

other browsers have not yet implemented any <strong>JavaScript</strong> support for XML, XPath, and XSLT.<br />

479

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!