Video-Based Tutorial: Page (1) of 1 - 05/19/10 Email this story to a friend. email article Print this page (Article printing at MyDmn.com).print page facebook

Real-World XML: Part 10 of 12

Understanding cross-browser actions with the Sarissa library By Joe Marini

XML technologies offer web developers and designers more flexibility than ever before. In Real-World XML, industry expert Joe Marini covers the best programming practices with XML, including the tools needed to build effective XML structures. He demonstrates the implementation of XML formats, how these formats work in real-world situations, and how they can facilitate project planning and development.

XML Essential Training is a prerequisite for getting the most out of this course.

Topics include:

*Understanding the Sitemap index format
*Integrating XML and design
*Using XML effectively in Firefox and Internet Explorer
*Avoiding common design mistakes
*Understanding and implementing DOM algorithms
*Building an XML tag set
*Using XML with RSS and Atom
*Processing XML data with XSLT

Understanding cross-browser actions with the Sarissa library

At this point we could take what we have learned using Firefox and Internet Explorer and the ways that they handle XML differently and we could sit down and write our own cross browser library for handling XML code.

Now thankfully we don't need to do that, because someone else already has and that library is known as the Sarissa Library and that's what we are going to cover in this section.

 


So the Sarissa Library is free open source library that's used for handling XML data and it was written by a guy named Emmanouil Batsis and it's available for download from the sarrisa. sourceforge.net website.

The Sarissa libraries essentially provide a cross browser way of working with XML.

Processing it, loading it, serializing it, transforming using XSLT, a whole bunch of cross browser support for common XML functions, and the API that it uses basically takes the best of both browsers, Firefox and IE, and creates one unified API for working with the XML content.

Now to use the Sarissa Library in your projects essentially all you need to do is include the sarissa.js file in the document where you want to use the functions and we'll take a look at few examples of that in a few moments.

Creating a document using the Sarissa Library is accomplished by calling getDomDocument() method with the namespace and root tag that you want to use and this code here works cross browser. So unlike Firefox or IE, you don't have to do any browser detection or write any special code; all you need to do is call the getDomDocument method.


Click Play or press spacebar to start or stop video

So looking at the previous examples that we have used in both the Firefox and IE sections, what we have done here is changed the way we instantiate the XML document to just call the Sarissa Library's getDomDocument method and we are passing in two empty strings here, and then it's just a matter of using the standard DOM functions to create the document content.

So what Sarissa does is it creates an XML document that's native to the browser that you are in. But the way that it crates the document is cross browser. And the reason why this works well is because recall that the DOM API for manipulating XML content once you have a document is the same in both browsers. So once we have the document instantiated using this line, the rest of the code is cross browser just by its very nature.

Sarissa also provides support for loading an XML document. In fact the asynchronous version for loading the document is the same as it is in the Internet Explorer. So if we look at the example here, you can see that the example for loading an XML document is slightly different because of the way you get the document. So here we are calling the getDomDocument function on the Sarissa Library and from that point forward it's pretty much the same in IE and Firefox. You set the async property to false and you just load the XML you want to load.

For the asynchronous case, the Sarissa Library emulates the Internet Explorer method inside of Firefox for you. So here we have our loadXMLDocumentAsync function and here we are instantiating the document by using the Sarissa Library's version and we set the asyn property to true. Now Sarissa implements the onreadystatechange and readystate properties in Firefox, so you can write the same code in IE and Firefox and it will just work cross browser.

The Sarissa Library also implements the Serializer and Parser objects that we saw in the earlier Firefox example, only these versions are cross browser and you can call the code the same way that you would in Firefox. So if we look at our parse.xml document example from earlier, you can see that the example pretty much looks exactly the way it would in Firefox only now once you have included the Sarissa Library, this code also work in Internet Explorer.

Okay, we have enough to see if we can go back, rewrite our earlier Firefox and Internet Explorer examples using the Sarissa Library, and test them in cross browser environment.


About lynda.com
www.lynda.com is an award-winning provider of educational materials, including Hands-On Training instructional books, the Online Training Library, CD- and DVD-based video training, and events for creative designers, instructors, students, and hobbyists.

The lynda.com Online Training Library and CD-ROM titles include such subjects as Photoshop, Flash, Dreamweaver, Illustrator, Office, digital photography, Web design, digital video, and many others. lynda.com's all-star team of trainers and teachers provides comprehensive and unbiased movie-based training to an international membership of tens of thousands of subscribers. Considering the speed at which technology evolves, the Online Training Library is a great solution for keeping your skills current. Library subscriptions begin as low as $25 a month, with no long-term commitment required.


Page: 1


Joe Marini is the director for Microsoft's Visual Studio Industry Partner program, and has been active in the Web and graphics industries for more than 15 years. He was an original member of the Dreamweaver engineering team at Macromedia, and has also held prominent roles in creating products such as QuarkXPress, mFactory's mTropolis, and Extensis QX-Tools. He is regularly a featured speaker at industry conferences and has authored or co-authored several books on Web development. His book The Document Object Model is widely regarded as the definitive resource for working with the DOM.

 


Related Keywords:xml, Extensible Mark-Up Language, xml training, xml tutorial, xml techniques, xml design, web design, web site design, Sarissa library

HOT THREADS on DMN Forums
Content-type: text/html  Rss  Add to Google Reader or
Homepage    Add to My AOL  Add to Excite MIX  Subscribe in
NewsGator Online 
Real-Time - what users are saying - Right Now!

Our Privacy Policy --- @ Copyright, 2015 Digital Media Online, All Rights Reserved