Library tutorials & articles

Reading, Storing and Transforming XML Data in .NET

Introduction

Unless you happened to be involved in some other career field, it would almost impossible to not realize that XML is steadily growing as a common data exchange format that can used be across any platform. As long as you conform to standard XML specifications, you can send your XML file anywhere, have it parsed or searched, and displayed as if it were perhaps on your local computer.

With .NET's arrival, reading data from a database, writing your results to an XML file, transforming it with an XSL stylesheet or even binding Web controls has become almost effortless, when compared to classic ASP. .NET offers developers many options with which they can manipulate and present data.

This article will illustrate a mixture of common .NET methods for formatting and presenting in a readable fashion any XML document you may encounter. The latest hype with XML Web services and even the .NET Framework itself relies on XML as its backbone, therefore this is no light matter. Furthermore, .NET offers numerous ways and XML objects for reading, writing and querying your XML. They primarily fall into three sections - Reading, Writing and Transforming XML, Storing and Manipulating your XML, and lastly Querying XML documents. In this article I'll demonstrate two of those. I'll use Net's more commonly used XML Document Object Model as part of the W3C DOM.

In this article, we will look at a few things:

  1. How to connect to a database and query it
  2. Writing or storing our search results to a local XML file
  3. Utilize the File System Object for some conditional testing
  4. Read our XML file from our local drive, transform and present it via XSL into our XML Web Control
  5. Lastly, we'll also use our performed XML document as a datasource and demonstrate the ease of binding a Datagrid Control with it

Comments

  1. 23 Mar 2005 at 14:16

    Hey Kurt,

    The xsl file is the xml transformation file which parses the xml into more readable html.
  2. 07 Dec 2004 at 07:40

    i might be very slow here, but what part of the code here are supposed to be used in the pubs.xsl file? yes, I am a newbie :-)


    Regards,
    Kurt
    Norway

  3. 18 Jan 2004 at 18:27

    Thanks - I'll check that and edit the article to fix it

  4. 12 Nov 2003 at 13:31

    Very good example, simple but contains a lot of information. Only one part I had to modify, in the XSL I had to change the criteria for the select from "PubsList/Pubs" to "PubsList/Table" as the child node is table and not pubs. I also had to grant write access to ASPNET account for the folder where I'm creating the XML.
    Thanks,


    Reem

  5. 01 Jan 1999 at 00:00

    This thread is for discussions of Reading, Storing and Transforming XML Data in .NET.

Leave a comment

Sign in or Join us (it's free).

Dimitrios Markatos Dimitrios, or Jimmy as his friends call him, is a .NET developer/architect who specializes in Microsoft Technologies for creating high-performance and scalable data-driven enterprise Web and deskto...

Related discussion

Related podcasts

Events coming up

  • Mar 15

    DevWeek 2010

    London, United Kingdom

    DevWeek is Europe’s leading independent conference for software developers, database professionals and IT architects, and features expert speakers on a wide range of topics, including .NET 4.0, Silverlight 3, WCF 4, Visual Studio 2010, REST, Windows Workflow 4, Thread Synchronization, ASP.NET 4.0, SQL Server 2008 R2, LINQ, Unit Testing, CLR & C# 4.0, .NET Patterns, WPF 4, F#, Windows Azure, ADO.NET, Entity Framework, Debugging, T-SQL Tips & Tricks, and more.

Want to stay in touch with what's going on? Follow us on twitter!