Manipulating XML data - using a DataSet

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Scott M. Lyon

    #1

    Manipulating XML data - using a DataSet

    Part of an application I'm working on needs to manipulate some XML data (in
    an XML file), by reading the data into a DataSet using the MyDataSet.ReadX ML
    method, and then using MyDataSet.Write XML to update the XML file itself.


    However, now I want to take advantage of the Primary Key functionality of
    the DataSet object, so I can easier find rows (in a DataTable in the
    DataSet), and also easier remove rows, based on a unique key.


    Unfortunately, I'm not sure how that will impact how the XML looks (and I
    cannot change the format of that file - it's already used by other
    applications).


    Here's a snippet of the XML I'm using:

    <?xml version="1.0" ?>
    <Cache>
    <FileCache>
    <FileName>Book1 .xls</FileName>
    <FilePath>C:\Wi ndows\Temp</FilePath>
    <OID>3838.64847 .26094.60105</OID>
    <DateTime>4/5/2005 9:50:45 AM</DateTime>
    </FileCache>
    <FileCache>
    <FileName>Book2 .xls</FileName>
    <FilePath>C:\Wi ndows\Temp</FilePath>
    <OID>3838.64847 .18503.25804</OID>
    <DateTime>4/5/2005 9:50:56 AM</DateTime>
    </FileCache>
    </Cache>


    The field I need to use as primary key (should be unique) is the OID field.

    As you can see, reading that data into a Dataset gives me a DataTable called
    Cache, with rows called FileCache (where OID is the third column in those
    rows).


    How do I tell it to use that column as the primary key, even after I've
    loaded it via the LoadXML method, and then how do I do the SaveXML without
    adding anything else to the XML layout than what you see above?


    Thanks!


  • Scott M. Lyon

    #2
    Re: Manipulating XML data - using a DataSet

    Never mind everybody... Managed to find the solution myself... :)

    If anyone else is having this issue, here's my solution.

    After the ReadXML, I added the following line:

    MyDataSet.Table s("Cache").Prim aryKey = New DataColumn()
    {_MyDataSet.Tab les("Cache").Co lumns("OID")}



    "Scott M. Lyon" <scott.RED.lyon .WHITE@rapistan .BLUE.com> wrote in message
    news:uessVSXfFH A.3692@TK2MSFTN GP09.phx.gbl...[color=blue]
    > Part of an application I'm working on needs to manipulate some XML data
    > (in an XML file), by reading the data into a DataSet using the
    > MyDataSet.ReadX ML method, and then using MyDataSet.Write XML to update the
    > XML file itself.
    >
    >
    > However, now I want to take advantage of the Primary Key functionality of
    > the DataSet object, so I can easier find rows (in a DataTable in the
    > DataSet), and also easier remove rows, based on a unique key.
    >
    >
    > Unfortunately, I'm not sure how that will impact how the XML looks (and I
    > cannot change the format of that file - it's already used by other
    > applications).
    >
    >
    > Here's a snippet of the XML I'm using:
    >
    > <?xml version="1.0" ?>
    > <Cache>
    > <FileCache>
    > <FileName>Book1 .xls</FileName>
    > <FilePath>C:\Wi ndows\Temp</FilePath>
    > <OID>3838.64847 .26094.60105</OID>
    > <DateTime>4/5/2005 9:50:45 AM</DateTime>
    > </FileCache>
    > <FileCache>
    > <FileName>Book2 .xls</FileName>
    > <FilePath>C:\Wi ndows\Temp</FilePath>
    > <OID>3838.64847 .18503.25804</OID>
    > <DateTime>4/5/2005 9:50:56 AM</DateTime>
    > </FileCache>
    > </Cache>
    >
    >
    > The field I need to use as primary key (should be unique) is the OID
    > field.
    >
    > As you can see, reading that data into a Dataset gives me a DataTable
    > called Cache, with rows called FileCache (where OID is the third column in
    > those rows).
    >
    >
    > How do I tell it to use that column as the primary key, even after I've
    > loaded it via the LoadXML method, and then how do I do the SaveXML without
    > adding anything else to the XML layout than what you see above?
    >
    >
    > Thanks!
    >[/color]


    Comment

    Working...