[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,
Re: Reading and Writing a XML file
Hi.
Do an acceptchanges at ds1 and try again.
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:
ds.WriteXml(xmlIncidentFile, XmlWriteMode.DiffGram)
and reading the xml file
vb Code:
ds1.ReadXml(xmlIncidentFile, XmlReadMode.DiffGram) 'There are no tables.
However, if i do the following it works ok.
vb Code:
ds.WriteXml(xmlIncidentFile)
and reading the xml file
vb Code:
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
Re: Reading and Writing a XML file
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