A
Archer
I have a xml document formed like:
<?xml version="1.0" standalone="yes"?>
<NewDataSet xmlns="http://www.myweb.com/Users.xsd">
<Users LastID="0">
<User>
<Name>Archer</Name>
<Password>Smc+mH0KDes=</Password>
</User>
<User>
<Name>John</Name>
<Password>oeB+HXGQMX8=</Password>
</User>
</Users>
</NewDataSet>
with the xsd file which is generated form above xml:
<?xml version="1.0"?>
<xs:schema id="NewDataSet"
targetNamespace="http://ioa.uestc.edu.cn/Users.xsd"
xmlns:mstns="http://ioa.uestc.edu.cn/Users.xsd"
xmlns="http://ioa.uestc.edu.cn/Users.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:element name="Users">
<xs:complexType>
<xs:sequence>
<xs:element name="User" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string" minOccurs="0" />
<xs:element name="Password" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="LastID" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="NewDataSet" msdata:IsDataSet="true"
msdata:Locale="zh-CN" msdata:EnforceConstraints="False">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element ref="Users" />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
I use a xmldatadocument object xddUsersto load the two files separately with
ReadXMLSchema and ReadXML method.
but when i use
DataRow dr=xddUsers.DataSet.Tables["User"].NewRow();
dr["Name"]=UserName;
xddUsers.DataSet.Tables["User"].Rows.Add(dr);
I get the modified XML like this:
<?xml version="1.0" standalone="yes"?>
<NewDataSet xmlns="http://www.myweb.com/Users.xsd">
<Users LastID="0">
<User>
<Name>Archer</Name>
<Password>Smc+mH0KDes=</Password>
</User>
<User>
<Name>John</Name>
<Password>oeB+HXGQMX8=</Password>
</User>
</Users>
<User> //pay attention to here,it is not in Users Element
<Name>Mike</Name>
<Password>Smc+mH0KDes=</Password>
</User>
</NewDataSet>
what could I do to add a new row in such case.Thanks a lot!
<?xml version="1.0" standalone="yes"?>
<NewDataSet xmlns="http://www.myweb.com/Users.xsd">
<Users LastID="0">
<User>
<Name>Archer</Name>
<Password>Smc+mH0KDes=</Password>
</User>
<User>
<Name>John</Name>
<Password>oeB+HXGQMX8=</Password>
</User>
</Users>
</NewDataSet>
with the xsd file which is generated form above xml:
<?xml version="1.0"?>
<xs:schema id="NewDataSet"
targetNamespace="http://ioa.uestc.edu.cn/Users.xsd"
xmlns:mstns="http://ioa.uestc.edu.cn/Users.xsd"
xmlns="http://ioa.uestc.edu.cn/Users.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:element name="Users">
<xs:complexType>
<xs:sequence>
<xs:element name="User" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string" minOccurs="0" />
<xs:element name="Password" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="LastID" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="NewDataSet" msdata:IsDataSet="true"
msdata:Locale="zh-CN" msdata:EnforceConstraints="False">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element ref="Users" />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
I use a xmldatadocument object xddUsersto load the two files separately with
ReadXMLSchema and ReadXML method.
but when i use
DataRow dr=xddUsers.DataSet.Tables["User"].NewRow();
dr["Name"]=UserName;
xddUsers.DataSet.Tables["User"].Rows.Add(dr);
I get the modified XML like this:
<?xml version="1.0" standalone="yes"?>
<NewDataSet xmlns="http://www.myweb.com/Users.xsd">
<Users LastID="0">
<User>
<Name>Archer</Name>
<Password>Smc+mH0KDes=</Password>
</User>
<User>
<Name>John</Name>
<Password>oeB+HXGQMX8=</Password>
</User>
</Users>
<User> //pay attention to here,it is not in Users Element
<Name>Mike</Name>
<Password>Smc+mH0KDes=</Password>
</User>
</NewDataSet>
what could I do to add a new row in such case.Thanks a lot!