Results 1 to 5 of 5

Thread: [RESOLVED] Reading and Writing a XML file

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Resolved [RESOLVED] Reading and Writing a XML file

    Hello,

    I am developing a PDA appliation using CF 2.0

    I am return a dataset from a web service. This is just one small table. This is so that the user can update this xml file
    without having to be connected to the internet. However there is a problem as when i change a value and acceptchanges and write
    the changes to the xml file. When i read in the same xml file, it does the give me the updated value. However, the change does happen
    in the actual xml file if I open it. But doesn't show when I read the xml using the dataset.

    Code:
     ds = ws.IncidentsByFilter() 'Filtered by 'in progess' and 'not started'.
     
     'Get the path of the incident xml file
     xmlIncidentFile = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.GetName.CodeBase)
     xmlIncidentFile = Path.Combine(xmlIncidentFile, "Incident.xml")
    
    ds.Tables(0).Rows(2)("Company") = "My new building"
     ds.AcceptChanges()
     'make some changes and Write the data to the xml file so this can be used offline
     ds.WriteXml(xmlIncidentFile)
    
    'Create an new dataset and read in the xml file so this can be used offline.
    Dim ds1 As New DataSet()
    xmlIncidentFile = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.GetName.CodeBase)
    xmlIncidentFile = Path.Combine(xmlIncidentFile, "Incident.xml")
    ds1.ReadXml(xmlIncidentFile)
    company = ds1.Tables(0).Rows(2)("Company").ToString() 'No change to the original value

    Can anyone see what mistakes I am making with the above.

    Many thanks,
    steve

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Reading and Writing a XML file

    Hi.
    Do an acceptchanges at ds1 and try again.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: Reading and Writing a XML file

    Hello,

    Problem seemed to off solved itself. Not sure what I did.

    However, I have a new problem with writing to the xml file using the DiffGram mode.

    I am doing this to write to the xml file
    vb Code:
    1. ds.WriteXml(xmlIncidentFile, XmlWriteMode.DiffGram)

    and reading the xml file
    vb Code:
    1. ds1.ReadXml(xmlIncidentFile, XmlReadMode.DiffGram) 'There are no tables.

    However, if i do the following it works ok.

    vb Code:
    1. ds.WriteXml(xmlIncidentFile)

    and reading the xml file
    vb Code:
    1. ds1.ReadXml(xmlIncidentFile) 'Table read in.

    However, I need to get the DiffGram working as I need that to track changes.

    Any reasons why I can't read in using the DiffGram.

    Many thanks for any help,

    Steve
    steve

  4. #4
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Reading and Writing a XML file

    Not used Diffgram but have a look.
    http://forums.microsoft.com/MSDN/Sho...48565&SiteID=1

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: Reading and Writing a XML file

    Problem solved.

    In using the DiffGram you also have to write in the schema as well. Then you can read the DiffGram. If there is no schema then it will read in a empty xml file.

    Thanks
    steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width