Click here to Skip to main content
15,883,809 members
Articles / Programming Languages / XML

Towards a Declarative SAX Framework : Part 1 - A Simple SAX-to-C#-Mapping

Rate me:
Please Sign up or sign in to vote.
4.51/5 (15 votes)
20 May 200422 min read 62.7K   894   33  
This article demonstrates a simple but flexible way to read XML content without DOM
#region Copyright
/*********************************************************************************
 * Copyright (c) 2004 by Martin Friedrich										 *
 * Permission to freely distribute, modify and compile these sources and		 *
 * binaries as long as this copyright notice is included.						 *
 * Use of code on your risk!													 *
 * *******************************************************************************/
#endregion

namespace SaxParserSupport 
{
	/// <summary>
	/// Defines the API for XML elements that can have child elements, i.e.
	/// elements of XSD complexTypes.
	/// </summary>
	public interface XMLElement : XMLSimpleElement 
	{
		/// <summary>
		/// Looks up the <tt>XMLSimpleElement</tt> class that represents the XML
		/// element whose tag name is given by <tt>name</tt>. For elements that are
		/// prefixed by a XML namespace, the fully qualified name must as given
		/// by the <tt>System.Xml.XmlReader.Name</tt> must be given. If no 
		/// <tt>XMLSimpleElement</tt> can be found, <tt>System.Xml.XmlException</tt> is
		/// thrown.
		/// <seealso cref="SaxParserSupport.XMLSimpleElement"/>
		/// <seealso cref="SaxParserSupport.XMLDocument"/>
		/// </summary>
		/// <param name="name">The tag name of an possible child element</param>
		/// <returns>An instance of class <tt>XMLSimpleElement</tt></returns>
		/// <exception cref="System.Xml.XmlException">No matching 
		/// <tt>XmlSimpleElement</tt> class found.</exception>
		XMLSimpleElement lookupElement( string name );

		/// <summary>
		/// Adds an instance of <tt>XMLSimpleElement</tt> that is to treated as a child
		/// element.
		/// </summary>
		/// <param name="el">The element to be added</param>
		void addElement( XMLSimpleElement el );

		/// <summary>
		/// Removes a child element.
		/// </summary>
		/// <param name="el">The child element to be removed</param>
		void removeElement( XMLSimpleElement el );

		/// <summary>
		/// Callback to be executed for mixed content XML elements on encountering
		/// chunks of text. In DOM terminoly, this is the case with TextNodes
		/// </summary>
		/// <param name="txt">Contains the current chunk of text.</param>
		void onText( string txt );

		/// <summary>
		/// Callback to be executed on encountering significant whitespace.
		/// </summary>
		/// <param name="txt">Contains the encountered whitespace sequence</param>
		void onSignificantWhitespace( string txt );

		/// <summary>
		/// Callback to be executed on encountering whitespace sequences.
		/// </summary>
		/// <param name="txt">Contains the whitespace sequence.</param>
		void onWhitespace( string txt );

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Germany Germany

Still lacking an university degree in computer science, I have 20 years of experience in software development and implementation. Having expert knowledge in object-oriented programming languages like C++, Java and C# on Windows, LINUX and UNIX platforms, I participated in multiple research projects at the University of Oldenburg. During these assignments, I was trusted with implementation of a graphical editor for specification languages like CSP or Z and a prototypical tool for workflow data distribution and analysis. I gained experiences in a widespread spectrum of CS and software development topics, ranging from compiler construction across data base programming to MDA. My research interests include questions of graphical user interface design and component-based systems.


I consider myself an old-school CS geek. While I admit that simple tasks do not pose much of a problem and can be done in quick and efficient manner, it's the challenging ones that appeal to me. If you are looking for a skillful employee - be it on a permanent, contract or freelance basis - and if you can live with a lacking university degree, why not contacting me?


Comments and Discussions