Link to home
Start Free TrialLog in
Avatar of mgmhicks
mgmhicks

asked on

Adding Records to and Updating XML Documents

I have a portable computer that is not connected to network, so we use xml documents for the program.  My quesion is i know how to bring in tables to a dataset and the write the xml document.  What I dont know is how to get the xml document and either add a new record to it, or change a existing record.  The idea being, guy picks a apartment to inspect.  If a record already exists for the that apartment, I want to be able to edit the record, if not I need to add a new record.  Could someone show me that best way to handle this, use a dataset or use xmldocument or what.  I am using VS 2008 and vb
Avatar of nepaluz
nepaluz
Flag of United Kingdom of Great Britain and Northern Ireland image

Can you provide an example of the xml file you want to load for us to give code suggestions?

What you basically need to do is to load the xml file into an XDocument and make that the datasource to a datagridview. You can then amend, add, remove records from that point.
Avatar of mgmhicks
mgmhicks

ASKER

Here is the stucture of the xml file.  It is a master and details table.  I will need to add records to both if its a new inspection, and edit the detail records if the inspection exists in the file.  The details records, if the item exists will be listed in listview control, and then I may need to add items to listview control or delete them whiling editing the record.  If its a new record, it doesnt already exists in the xml file, then I would need to append to the master and detail tables, the new record when it is saved.  In this mode my listview isnt bound to datasource and I just want to add the record when the person hits the save button.

Thank you for helping
<?xml version="1.0" standalone="yes"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="Inspections">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="ID" type="xs:int" minOccurs="0" />
              <xs:element name="WO_Number" type="xs:string" minOccurs="0" />
              <xs:element name="WO_Description" type="xs:string" minOccurs="0" />
              <xs:element name="Total_Company" type="xs:decimal" minOccurs="0" />
              <xs:element name="Total_Resident" type="xs:decimal" minOccurs="0" />
              <xs:element name="Invoiced" type="xs:boolean" minOccurs="0" />
              <xs:element name="CreatedDate" type="xs:dateTime" minOccurs="0" />
              <xs:element name="LastEditDate" type="xs:dateTime" minOccurs="0" />
              <xs:element name="InspectedBy" type="xs:string" minOccurs="0" />
              <xs:element name="ID1" type="xs:int" minOccurs="0" />
              <xs:element name="MasterID" type="xs:int" minOccurs="0" />
              <xs:element name="ItemID" type="xs:int" minOccurs="0" />
              <xs:element name="ItemGroup" type="xs:string" minOccurs="0" />
              <xs:element name="ItemDescription" type="xs:string" minOccurs="0" />
              <xs:element name="ItemPrice" type="xs:decimal" minOccurs="0" />
              <xs:element name="ResidentCharge" type="xs:boolean" minOccurs="0" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

Open in new window

The schema you provided is OK, however I wonder, are you looking for a solution to this project or are you stuck on somehting specific that you need help with?

I can help you with the specific issues that you may come accros in the project, however, there is not much on that from your quetion.

If you require the entire class to accomplish this, could you state so?
Really wondering what is the best approach for starters.  Import xml document to a dataset and work with that or is it best to put into  a xmldocument object and work with it from there?  
if you intend to regularly update the data, then importing / attaching the xml to a dataset is my recomendation. Ofcourse, if the file can be used by several people at the same time, then this would givemore gravity to my recomendation.
OK, so I look if the inspections.xml files.  If it does exist I do a ds.readxml and import the xml file to the dataset.  Once there, I have to check if the work order he clicked already exists in the dataset. And then go to that record, in both the master and detail tables and bind the listview to the details and the master columns to other text boxes.  If it doesnt exits do I just import the schema xml file to get structure and then add records from that dataset.  ie  ds.readxmlschema do I can get the sturcture then add records to that dataset.  Is it best to combine both tables in 1 xml or is it better to have seperate xml files for the master and detail records.  
thanks
the schema defines the structure of the xml, thus the data validation. And yes, you can use both or just the xml. Remember if you bind your listview to the dataset, then the listview will have ALL the columns available in the schema definition. Just entering the data would be adequate, but he schema would help in the element validation routine when you get to save your data back.

It sounds convoluted, but the existence of the schema actually simplifies the whole authoring of the xml.
So if the xml file doesnt exits read the schema into the dataset and then I will be able to update the dataset from there correct.  Also the idea of using a dataset with 2 tables (master and detail) or a dataset that has one table with combined dataset.  I'm thinking I should have 2 seperate files and set a relationship is that what you are thinking?  I am going to accept your solution, but stay posted I will have several more issues before this is done I'm sure.

thanks
ASKER CERTIFIED SOLUTION
Avatar of nepaluz
nepaluz
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thankk you that helps alot.  Stay tuned.