XSD problem

S

Steven Blair

I have been supplied an xsd file.
This represents a message I must send a client.

My approach to build the message is as follows:

DataSet ds = new DataSet();
ds.ReadXmlScheme("myfile.xsd");

This give me a DataSet with a number of tables.
In the xsd document, there is a table called policy_details.
This table is made up of 6 elements, but one element actually relates to
another table (policy_premium):

This means the DataSet actually has a table called policy_details and
policy_premium.
I create a new row for policay_details, populate required fields, and do
the same for policy_premium:

tableName = "policy_premium";
dr = ds.Tables[tableName].NewRow();
dr["policy_premium_text"] = "1058.11";
dr["policy_details_id"] = "1";

ds.Tables[tableName].Rows.Add(dr);

At the end of this I do:

ds.WriteXML(_strWriter, XmlWriteMode.IgnoreSchema);
string strPost = _strWriter.ToString();

This creates the document I expected except the policy_premium is the
last field in the policy_details, but according to the xsd this field
should be the fourth. This means the message fails validation.

Can anyone explain how I can get the XML to render in the same order as
the xsd file, or have I taken the wrong approach to this problem?

Steven
 
N

Nicholas Paldino [.NET/C# MVP]

Steven,

Can you post an example (schema and code used to create an instance of
the schema) for us to see?
 
S

Steven Blair

The schema is a very big file, but the section I am having trouble is
below:

<xs:complexType>
<xs:sequence>
<xs:element ref="policy_insurer_code" />
<xs:element ref="policy_covertype_code" />
<xs:element ref="policy_number" />
<xs:element ref="policy_premium" />
<xs:element ref="policy_inception_date" />
<xs:element minOccurs="0" maxOccurs="1" ref="policy_refundable"
/>
</xs:sequence>
<xs:attribute default="N" name="renewal_status">
<xs:simpleType>
<xs:restriction base="xs:NMTOKEN">
<xs:enumeration value="Y" />
<xs:enumeration value="N" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="policy_insurer_code" type="xs:string" />
<xs:element name="policy_covertype_code" type="xs:string" />
<xs:element name="policy_number" type="xs:string" />
<xs:element name="policy_premium">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute default="GBP" name="currency">
<xs:simpleType>
<xs:restriction base="xs:NMTOKEN">
<xs:enumeration value="GBP" />
<xs:enumeration value="EUR" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="policy_inception_date" type="xs:string" />

And my code for building up the structure:

_xmlSource = new DataSet();
_xmlSource.ReadXmlSchema(config._schemaFile);
_xmlSource.Namespace = String.Empty;

//policy_details
tableName = "policy_details";
dr = ds.Tables[tableName].NewRow();

dr["loan_details_id"] = "1";
dr["policy_details_id"] = "1";
dr["policy_insurer_code"] = "UK_INS_10173";
dr["policy_covertype_code"] = "COVER_TYPE_1084";
dr["policy_number"] = "123456";

dr["policy_inception_date"] = "02-OCT-2007";
dr["policy_refundable"] = "Y";

ds.Tables[tableName].Rows.Add(dr);

//policy_premium
tableName = "policy_premium";
dr = ds.Tables[tableName].NewRow();
dr["policy_premium_text"] = "1058.11";
dr["policy_details_id"] = "1";

ds.Tables[tableName].Rows.Add(dr);

//Then render to a string
StringWriter _strWriter = new StringWriter();
ds.WriteXml(_strWriter, XmlWriteMode.IgnoreSchema);
strPost = _strWriter.ToString();

I am just not sure I am using the correct technique for this problem, so
any help would be appreciated.

Steven
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top