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.

You might also like...

Comments

About the author

Chris Scott

Chris Scott United States

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 sta...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Debuggers don't remove bugs. They only show them in slow motion.”