writexml将新数据和现有数据追加到文件中 [英] writexml appends new and existing data to file
问题描述
我尝试了在线帮助和Goggle,但找不到任何答案.当我在创建新的项目"行之后调用dataset.WritXML(string文件名)时,我的程序似乎先写入所有现有行,然后写入新行,然后再次重复所有现有行.在启动程序之后并保存之前,我尝试删除XML文件,以查看它是否只是将数据追加到现有文件中,但是我仍然得到相同的输出.我已经在调试时查看了数据集的值,它们看起来很好,没有重复的行.
我认为我的架构文件可能有问题:
<? xml 版本 =" 编码 =" utf-8" >
< xs:schema id =" xmlns " xmlns:xs =" http://www.w3.org/2001/XMLSchema" xmlns:msdata urn:schemas-microsoft-com:xml-msdata" >
< xs:element 名称 =" msdata:IsDataSet true" msdata:UseCurrentLocale true" < xs:complexType >
< xs:choice 最小发生 =" maxOccurs 无限制" < xs:element 名称 =" < xs:complexType >
< xs:sequence >
< xs:element 名称 =" 类型 xs :字符串" minOccurs 0" msdata:Ordininal =" >
< xs:element 名称 =" 类型 xs :字符串" minOccurs 0" msdata:Ordininal =" >
< xs:element 名称 =" minOccurs 0 " maxOccurs 无界" < xs:complexType >
< xs:sequence >
< xs:element 名称 =" 类型 xs :字符串" minOccurs 0" / >
< xs:element 名称 =" 类型 xs :字符串" minOccurs 0" / >
< /xs:sequence >
< /xs:complexType >
< /xs:element >
< xs:element 名称 =" minOccurs 0 " maxOccurs 无界" < xs:complexType >
< xs:sequence >
< xs:element 名称 =" 类型 xs :字符串" minOccurs 0" / >
< xs:element 名称 =" 类型 xs :字符串" minOccurs 0" / >
< /xs:sequence >
< /xs:complexType >
< /xs:element >
< /xs:sequence >
< xs:attribute 名称 =" 类型 xs :字符串" / > 跨度>
< /xs:complexType >
< /xs:element >
< /xs:choice >
< /xs:complexType >
< /xs:element >
< /xs:schema >
谁能看到任何错误?
我的猜测是您的DataSet中有两个表,并且它们都被写出了. /blockquote>
原来我正在读取XML文件几次,而没有先清除旧数据.奇怪的是,我调试时IDE并未显示多余的行.
I''ve tried online help and Goggle and I can''t find any answer to this. When I call dataset.WritXML(string filename) after creating a new "Project" row my program appears to write all the existing rows then the new row and then repeats all the existing rows again. I''ve tried deleting the XML file after starting the program and before saving to see if it was just appending the data to the existing file but I still get the same output. I''ve looked at the dataset value when debugging and they look fine, no repeated rows.
I think there might be a problem with my schema file:
<?xml version="1.0" encoding="utf-8"?> <xs:schema id="ProjectCommander" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xs:element name="ProjectCommander" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"> <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element name="Project"> <xs:complexType> <xs:sequence> <xs:element name="LastChangeNotice" type="xs:string" minOccurs="0" msdata:Ordinal="0" /> <xs:element name="LastSiteInstruction" type="xs:string" minOccurs="0" msdata:Ordinal="1" /> <xs:element name="MilestoneItem" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="Date" type="xs:string" minOccurs="0" /> <xs:element name="Event" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="CommentItem" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="Date" type="xs:string" minOccurs="0" /> <xs:element name="Description" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="ProjectID" type="xs:string" /> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> </xs:element> </xs:schema>
Can anyone see anything wrong?解决方案My guess is that you have two tables in your DataSet and they are both being written out.
Turns out I was reading the XML file a couple times without clearing the old data first. Odd thing is the IDE didn''t show the extra rows when I was debugging.
这篇关于writexml将新数据和现有数据追加到文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!