All,
I am trying to read an XML of a set of records (an "order") from one machine
and then turn it into a set of records on another machine. But some of the
order's dependent records are optional, and I'd like to continue to bypass
them when the original user bypassed them.
This set spans four tables. One is the header table and the other three are
all subject to it. These three are misc charge, instruction, and detail. For
any given order, the misc charge and instruction data are "optional" - the
order can go without records in them - but an order must have at least one
detail record.
Say someone sends the simplest possible valid order.
=================================================
The XML we get is:
<OrderDump>
<order_header order_number="B948124C-8C42-7714-91B5-05E4A8F84DC3">
<order_name>My Order</order_name>
<order_miscellaneous_charge />
<order_instruction />
<order_detail>
<upc>1094723</upc>
</order_detail>
</order_header>
</OrderDump>
=================================================
Here is the schema (XSD):
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop">
<xsd:element name="OrderDump">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="order_header" sql:relation="order_header">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="order_name" type="xsd:string" minOccurs="1" />
<xsd:element name="order_miscellaneous_charge"
sql:relation="order_miscellaneous_charge" nillable="true">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="transaction_code" type="xsd:string"
minOccurs="0" />
<xsd:element name="amount" type="xsd:float" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="order_instruction"
sql:relation="order_instruction" nillable="true">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="instruction_type" type="xsd:string"
minOccurs="0" />
<xsd:element name="message_text" type="xsd:string" minOccurs="0"
/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="order_detail" sql:relation="order_detail">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="supc" type="xsd:string" minOccurs="1"
maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="order_number" type="xsd:string" />
</xsd:complexType>
<xsd:key name="order_headerKey1" msdata:PrimaryKey="true">
<xsd:selector xpath="." />
<xsd:field xpath="@order_number" />
</xsd:key>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
=================================================
Here is my code (C# 1.1.4322):
string xmlFilename = @"C:\OrderDump.XML";
DataSet orderDumpDataSet = new DataSet();
orderDumpDataSet.ReadXmlSchema(@"C:\OrderDump.xsd" );
XmlTextReader reader = new XmlTextReader(xmlFilename);
XmlDataDocument document = new XmlDataDocument(orderDumpDataSet);
document.Load(reader);
=================================================
This code treats the XML's placeholders in _misc_charge and _instruction
(<order_miscellaneous_charge /> and <order_instruction />, respectively) as
valid records, and inserts a bogus row for each (with mostly NULL values)
into orderDumpDataSet.Tables[1] and [2]. This is Bad.
It'd be nice if we could apply a setting to the XSD, orderDumpDataSet, or
XmlDataDocument - informing the object's consumers that when the XML gives
nothing but a placeholder for these tables, then (for this instance) the
DataSet should record no DataRow in their respective DataTables.
Is this possible? Or am I going to have to search through the DataTables and
weed out the null values later? (Which is certainly possible, but a pain.)
--
zimriel sbc dot
at global net
..
http://pages.sbcglobal.net/zimriel/
*new improved shorter .sig*