Library tutorials & articles

Searching XML using a DataSet & DataView

Introduction

Sometimes you need the basic features of a database but don't want the hassle, and possibly cost, of creating one for a small application. With the .NET DataSet object and a simple XML document we can emulate the basic features of a database. In this example, we use an XML document which stores our product information. We want to look up a product by SKU and return the price and description to a Web page.

We have three products in our list. The following is a basic XML document, productlist.xml, containing our data:

<?xml version="1.0" encoding="utf-8" ?>
<ProductList>
<Products>
    <SKU>1</SKU>
    <Price>100.00</Price>
    <Description>Widget #1</Description>
</Products>
<Products>
    <SKU>2</SKU>
    <Price>10.00</Price>
    <Description>Widget #2</Description>
</Products>
<Products>
    <SKU>3</SKU>
    <Price>30.00</Price>
    <Description>Widget #3</Description>
</Products>
</ProductList>

If you think of this document in terms of a database, the data within the ProductList tags are our database. The data within the Products tags are a table in the database. SKU, Price, and Descriptions are columns in the Products table. Just like a database, we want to return a row of values, given a column value.

Comments

  1. 05 Aug 2006 at 18:29

    Now wat if we attach an attribute to Description element.how will this be handled then using c#   ?????if products is the table and description is the column in it then wat will be the attribute be if attached to description and how will we retrieve the the element named 'description' without retrieving th attribute and also tell the way of retrieving the attribute?

    samn          

  2. 01 Jan 1999 at 00:00

    This thread is for discussions of Searching XML using a DataSet & DataView.

Leave a comment

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

Chris Scott Chris Scott is the founder of Host Orlando (www.hostorlando.com) a Web hosting and development company in Orlando, FL specializing in Microsoft technologies. A self-taught programmer, Chris started...

Related discussion

Related podcasts

  • Episode 10: LINQ

    K Scott leads us in a discussion of LINQ, including: What is it How introducing LINQ to .NET changed the framework LINQ Providers LINQ to XML LINQ to SQL - how it's different from EF, tips and tricks, when to use it Links: LINQpad 3rd Party LIN...

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!