advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the code for this article
Build a Lightweight XML DOM Parser with C#
Can you think of ways to make this parser more efficient? Do you have general parsing tips or comments?
Partners & Affiliates
advertisement
advertisement
Average Rating: 4/5 | Rate this item | 3 users have rated this item.
 Print Print
 
Build Your Own Lightweight XML DOM Parser
Microsoft's MSXML parser is rich in functionality, but in some cases a full-featured parser is too large for resource-limited environments. Don't count XML out yet though; you can write your own lightweight VB XML parser in fewer than 400 lines of code! 

advertisement
Editor's Note: This tutorial is also available in a version for Java developers. Get the Java version.

ML is rapidly gaining popularity with application developers as a data storage and exchange format because of its readability, ease of use, and firewall friendliness. Microsoft's full-featured MSXML parser is large and powerful—and consumes resources commensurate with that power at installation and run time. The MSXML parser is well over 1MB.



Full-featured XML parsers offer rich functionality; they support XML namespaces, DTD and schema validation, multiple character-set encodings, etc.; however, not every real-world project requires all that functionality. An application may need only a simple data transfer protocol within a closed environment, or may work with XML data that's always valid and uses only simple ASCII characters. Under those circumstances, employing a full-blown XML parser is probably overkill. Furthermore, if you're deploying the application over the Web or to a handheld device, network bandwidth or system memory constraints may make using a full-featured XML parser unpalatable.

Enter the SimpleDOMParser
The SimpleDOMParser is a highly simplified and ultra-lightweight XML DOM parser written in pure VB. The source code is fewer than 400 lines long.

Obviously, with such a small code base, the SimpleDOMParser won't support XML namespaces, understand multiple character-set encoding, or validate documents against a DTD or schema; but what the SimpleDOMParser can do well is parse a stream of well-formed XML tags into a DOM-like element tree, letting you perform the common task of extracting data from XML-formatted text.

Why use DOM as a model rather than SAX? The DOM provides an easier-to-use programming interface than SAX. Unlike SAX, when you process an XML document as a DOM tree, all the information within the document is always available. Although the SAX parsing model provides better performance and far less memory usage than the DOM model, most developers have, at times, found themselves building a complete or partial DOM tree anyway when using SAX. Using SAX, an application processes only one tag at a time. If other tags' contents have to be utilized during the processing, you must maintain some sort of global state throughout the process. Maintaining that global state is essentially the purpose of the DOM model. Still, many small XML applications don't need the full DOM model. Therefore, the SimpleDOMParser provides access to tag names, hierarchy, and content but doesn't bother with many features found in the full W3C DOM specification.

  Next Page: Simplifying the DOM Model


Page 1: IntroductionPage 3: Defining XML Parsing Primitives (cont'd)
Page 2: Simplifying the DOM ModelPage 4: XML Parsing Strategy and SimpleDOMParser Implementation
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM eBook: Planning a Service Oriented Architecture
IBM eBook: Choosing the Right Architecture--What It Means for You and Your Business
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Avaya Article: Using Intelligent Presence to Create Smarter Business Applications
Intel Go Parallel Article: Getting Started with TBB on Windows
Microsoft Article: 7.0, Microsoft's Lucky Version?
Avaya Article: How to Feed Data into the Avaya Event Processor
IBM Article: Developing a Software Policy for Your Organization
Microsoft Article: Managing Virtual Machines with Microsoft System Center
Intel Go Parallel Article: Intel Threading Tools and OpenMP
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Silverlight 2 App and Walkthrough: Leverage Silverlight 2 with SQL Server and XML
IBM Article: Enterprise Search--Do You Know What's Out There?
HP Demo: StorageWorks EVA4400
Microsoft Article: The Progress and Promise of Deep Zoom
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES