Oleg,
Save the following as XMLSchema.xsd
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="XMLSchema" targetNamespace="XMLSchema.xsd"
elementFormDefault="qualified" xmlns="XMLSchema.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="customerdetails">
<xs:sequence>
<xs:element name="name"
type="xs:string" />
<xs:element name="surname"
type="xs:string" />
<xs:element name="addressline1"
type="xs:string" />
<xs:element name="addressline2"
type="xs:string" minOccurs="0" />
<xs:element name="addressline3"
type="xs:string" minOccurs="0" />
<xs:element name="postalcode"
type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:element name="orders">
<xs:complexType>
<xs:sequence>
<xs:element name="order"
minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="orderid" type="xs:string" />
<xs:element name="orderdate" type="xs:dateTime"
minOccurs="0" />
<xs:element name="customer"
type="customerdetails" minOccurs="1" />
<xs:element name="shipto" type="customerdetails"
minOccurs="0" />
<xs:element name="value" type="xs:decimal" />
<xs:element name="expirydate"
type="xs:gYearMonth" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Next save this as sample.xml
<?xml version="1.0" encoding="utf-8" ?>
<orders xmlns="XMLSchema.xsd">
<order>
<orderid>12345</orderid>
<customer>
<name>Joe</name>
<surname>Bloggs</surname>
<addressline1>Somewhere</addressline1>
<postalcode>AB123CD</postalcode>
</customer>
<value>10.99</value>
<expirydate>2005-03</expirydate>
</order>
</orders>
Finally, run the following piece of VB.NET.
Public Sub Main()
Dim ds As New DataSet
Dim dt As DataTable
Dim row As DataRow
Dim xmlDoc As XmlDataDocument
' Update the document using a set
ds.ReadXmlSchema("..\XMLSchema.xsd")
xmlDoc = New XmlDataDocument(ds)
xmlDoc.Load("..\Sample.xml")
' Add the shipping address
dt = ds.Tables("shipto")
row = dt.NewRow
row!order_id = ds.Tables("order").Select
("orderid='12345'")(0)!order_id
row!name = "John"
row!surname = "Doe"
row!addressline1 = "Somewhere"
row!postalcode = "ABC1234"
dt.Rows.Add(row)
xmlDoc.Save("c:\temp\updatedbydataset.xml")
End Sub
The output file, c:\temp\updatedbydataset.xml will not
pass schema validation as the new shipping address is
added to wrong part of the document.
Modifing the expirydate field will also cause the
document to fail validation.
Regards
Oliver
-----Original Message-----
Oliver Tamayo wrote:
I'm trying to do the same. I've managed to open the
xml, updated/appended to it and saved it. The resulting
document now fails schema validation as any new fields
are not added to document in the correct sequence.So you must be doing something wrong, right?
Show us your code and expalain what are you trying to
achieve.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel
.