About UsMy AccountView Cart
Browse or Search over 5 million articles »
Find Articles by Publication

Home | Industry Information | Business News | Browse by Publication | X | XML Journal

Processing XML with C# and .NET: a solution that's simpler than you might expect.(.NET)

Article, News, Research, Information, Industry & Business News
» View article excerpt

Read this article now - Try Goliath Business News - FREE!  
You can view this article PLUS...

  • Over 5 million business articles
  • Hundreds of the most trusted magazines, newswires, and journals (see list)
  • Premium business information that is timely and relevant
  • Unlimited Access
Now for a Limited Time, try Goliath Business News - Free for 7 Days!
Tell Me More Terms and Conditions

Purchase this article for $4.95

Already a subscriber? Log in to read full article
 

Publication: XML Journal
Publication Date: 01-JAN-04
Delivery: Immediate Online Access
Author: Solymosi, Andrew

Article Excerpt
Microsoft's counterpiece to Java, the new C# programming language with its rich .NET library, uses XML as a core technology. This article presents some basic ideas, for example creating and manipulating a DOM tree, and reading and writing XML streams.

I also compare .NET's solution with the SAX model, and finally I show how a complex XSLT algorithm can be more simply implemented in C#. The source code can be downloaded from www.sys-con.com/xml/sourcec.cfm.

XML Processors

To process an XML document means to extract information from it. Often the extracted information should be output to a new XML (or perhaps HTML) document that's similar to the original one-then we address the transformation.

Which processor to use for a given task is not a trivial question. There are a number of ready-to-use XML processors on the market--like Cocoon and Axkit--and any XML-enabled browser (like Netscape Navigator 8 or Microsoft Internet Explorer 6.0) has a built-in XML, processor. They require processing instructions, which can be contained in an XSLT document tot complex operations. XSLT is, however, a special style and not a very convenient programming language. Many would prefer to fiddle around with well-known, conventional programming structures from C++ or Java. For them, a real alternative is to write their own XML processor. Modern programming languages like C# and lava offer great support for this task in the form of class libraries; in the case of C#, these are .NET classes.

Processing Methods

There are two ways to process an XML document: online and offline. Offline processing means not being connected to the XML source, so the document has to be loaded (typically as a DOM tree) into memory beforehand. In the space-time trade, you lose space (memory) but gain time (speed) for the processing. This is the best method if most parts of the document are going to be processed, especially if they're going to be processed repeatedly.

Online processing (reading the document piece by piece) can be slow, but it works with less memory. It is advantageous if only certain parts of the document will be processed, or if the processing is sequentially straightforward.

C#'s built-in .NET library provides all the classes necessary for processing an XML document both ways. They are placed in the System.Xml namespace (with its nested namespaces System.Xml.Schema, System.Xml.Xsl, etc.).

The abstract classes XmlReader/XmlWriter provide the basis for online processing; XmlReader represents a fast, read-only forward cursor in an XML stream, while XmlWriter provides an interface for producing XML streams. The basis for offline processing is the class System.Xml.XmlDocument (with its superclass XmlNode) representing an XML document as a DOM tree (i.e., memory intensive). We'll investigate this option first.

Creating an XML Document

The XmlDocument constructor (usually called without parameters) creates an empty in-memory XML document. its methods, like InsertBefore, InsertAfter, and AppendChild, build the DOM tree in memory. They need XmlNode parameters, which can be created by the XmlDocument's method CreateXxx, where Xxx stands for Element, Attribute, Node, Comment, ProcessingInstruction, CDataSection, DocumentFragment, XmlDeclaration, DocumentType, or EntityReference. They create a node in the context of the document but don't attach it to the tree:

XmlDocument doc = new XmlDocument (); // empty XmlElement elem = doc.CreateElement ("NewAndOnlyElement"); // XmlElement is...

NOTE: All illustrations and photos have been removed from this article.



More articles from XML Journal
XML for client-side computing, 01-MAR-04
Leveraging XML knowledge to design, develop, and deploy speech applications: packaged apps ease the process, 01-MAR-04
Application integration: addressing the issues: one-stop shopping is not a reality, 01-MAR-04

Looking for additional articles?
Click here to search our database of over 3 million articles.

Looking for more in-depth information on this industry?
Click here to search our complete database of Industry & Market reports by text, subject, publication name or publication date.

About Goliath
Whether you're looking for sales prospects, competitive information, company analysis or best practices in managing your organization, Goliath can help you meet your business needs.

Our extensive business information databases empower business professionals with both the breadth and depth of credible, authoritative information they need to support their business goals. Whether it be strategic planning, sales prospecting, company research or defining management best practices - Goliath is your leading source for accurate information.

Home

Company Profiles

Industry Information

Business Development Resources

Business Management Resources

U.S. Job Search

Need More Information?
Start a new search.
Advertising, Privacy Policy, Refund Policy, Contact Us, Site Map, Terms & Conditions, Add to del.icio.us
Customer Service, How to Buy, Frequently Asked Questions
Copyright © 2008, ECNext, Inc., All Rights Reserved