I have a project with a supplied schema file and a supplied example
output xml document. Using the typed dataset classes I have not been
able to overcome the erroneous output xml. Any help would be greatly
appreciated.
First the supplied xsd:
<?xml version="1.0" ?>
<xs:schema id="JournalEntrySchema"
targetNamespace="urn:schemasm3ascom:DataWatchJournalEntry"
xmlns:mstns="urn:schemasm3ascom:DataWatchJournalEntry"
xmlns="urn:schemasm3ascom:DataWatchJournalEntry"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemasmicrosoftcom:xmlmsdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:element name="AccKnowledge">
<xs:complexType>
<xs:sequence>
<xs:element name="Company" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="mstns:akID" minOccurs="0" />
<xs:element name="Property" minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="mstns:akID" minOccurs="0" />
<xs:element name="JournalEntry" minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="PostDate" type="xs:date" minOccurs="0"
/>
<xs:element name="Description" type="mstns:akString100"
minOccurs="0" />
<xs:element name="Notes" type="mstns:akString200"
minOccurs="0" />
<xs:element name="Detail" minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="AccountNumber" type="xs:decimal"
minOccurs="0" />
<xs:element name="Amount" type="mstns:akAmount"
minOccurs="0" />
<xs:element name="TransactionType"
type="mstns:akTransactionType" minOccurs="0" />
<xs:element name="Description"
type="mstns:akString100" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="Type" form="unqualified" type="mstns:akType" />
<xs:attribute name="Customer" form="unqualified" type="xs:string"
/>
</xs:complexType>
</xs:element>
<xs:element name="NewDataSet" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element ref="AccKnowledge" />
</xs:choice>
</xs:complexType>
</xs:element>
<xs:simpleType name="akID">
<xs:restriction base="xs:string">
<xs:length value="3" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="akType">
<xs:restriction base="xs:string">
<xs:enumeration value="JournalEntry" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="akAmount">
<xs:restriction base="xs:decimal">
<xs:fractionDigits value="2" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="akString100">
<xs:restriction base="xs:string">
<xs:maxLength value="100" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="akString200">
<xs:restriction base="xs:string">
<xs:maxLength value="200" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="akTransactionType">
<xs:restriction base="xs:string">
<xs:enumeration value="C" />
<xs:enumeration value="D" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
and here is the expected output xml:
<?xml version="1.0" encoding="UTF-8" ?>
- <!-- Type attribute MUST be "JournalEntry" with EXACT case
-->
- <!-- Customer attribute must match customer name in authentication
database
-->
- <!-- The correct namespace (as shown in xmlns attribute) must be
used
-->
- <AccKnowledge xmlns="urn:schemas-m3as-com:DataWatch-JournalEntry"
Type="JournalEntry" Customer="A Customer">
- <Company>
- <!-- ID is the 3 character ID assigned to the company in
AccKnowledge and is required
-->
<ID>ABC</ID>
- <Property>
- <!-- ID is the 3 character ID assigned to the property in
AccKnowledge and is optional
-->
- <!-- if ID is ommitted the Journal Entry will be inserted at the
company level
-->
<ID>DEF</ID>
- <JournalEntry>
- <!-- JournalEntry child nodes are required except for Notes
-->
- <!-- PostDate must comply with the ISO 8601 standard (YYYY-MM-DD)
-->
<PostDate>2002-04-01</PostDate>
<Description>Payroll</Description>
<Notes>Some additional information here</Notes>
- <Detail>
- <!-- Detail child nodes are required except for Description
-->
- <!-- AccountNumber must be a valid GL Account number
-->
- <!-- Amount must be numeric with 2 decimal places
-->
- <!-- TransactionType must be "C" for credit or "D" for debit
-->
<AccountNumber>203.000</AccountNumber>
<Amount>1280.75</Amount>
<TransactionType>D</TransactionType>
<Description>Accounts Payable</Description>
</Detail>
- <Detail>
<AccountNumber>1584.001</AccountNumber>
<Amount>1280.75</Amount>
<TransactionType>C</TransactionType>
<Description>Equipment Repair</Description>
</Detail>
</JournalEntry>
</Property>
</Company>
</AccKnowledge>
and here is the actual output from my windows service:
<?xml version="1.0" standalone="yes" ?>
- <JournalEntrySchema
xmlns="urn:schemasm3ascom:DataWatchJournalEntry">
- <AccKnowledge Type="JournalEntry" Customer="Prism">
- <Company>
<ID>867</ID>
- <Property>
<ID />
- <JournalEntry>
<PostDate>2004-09-30T00:00:00.0000000-05:00</PostDate>
<Description>Journal Entry</Description>
<Notes />
- <Detail>
<AccountNumber>120307.000</AccountNumber>
<Amount>64.30</Amount>
<TransactionType>D</TransactionType>
<Description>USD-Accrl-Fedex</Description>
</Detail>
- <Detail>
<AccountNumber>60107.000</AccountNumber>
<Amount>761.40</Amount>
<TransactionType>D</TransactionType>
<Description>USD-Accrl-island oasis</Description>
</Detail>
- <Detail>
<AccountNumber>180319.000</AccountNumber>
<Amount>260.00</Amount>
<TransactionType>D</TransactionType>
<Description>KYD-Accrl-vigoro nursery</Description>
</Detail>
- <Detail>
<AccountNumber>180319.000</AccountNumber>
<Amount>50.00</Amount>
<TransactionType>D</TransactionType>
<Description>KYD-Accrl-vigoro nursery</Description>
</Detail>
- <Detail>
<AccountNumber>841.000</AccountNumber>
<Amount>1135.70</Amount>
<TransactionType>C</TransactionType>
<Description>USD / KYD AP Accruals</Description>
</Detail>
</JournalEntry>
</Property>
</Company>
- <Company>
<ID>773</ID>
- <Property>
<ID />
- <JournalEntry>
<PostDate>2004-09-15T00:00:00.0000000-05:00</PostDate>
<Description>Journal Entry</Description>
<Notes />
- <Detail>
<AccountNumber>50148.001</AccountNumber>
<Amount>3500.00</Amount>
<TransactionType>D</TransactionType>
<Description>Accrued 9/04 Bonus</Description>
</Detail>
- <Detail>
<AccountNumber>120148.001</AccountNumber>
<Amount>2500.00</Amount>
<TransactionType>D</TransactionType>
<Description>Accrued 9/04 Bonus</Description>
</Detail>
- <Detail>
<AccountNumber>140148.001</AccountNumber>
<Amount>1500.00</Amount>
<TransactionType>D</TransactionType>
<Description>Accrued 9/04 Bonus</Description>
</Detail>
- <Detail>
<AccountNumber>180148.001</AccountNumber>
<Amount>1000.00</Amount>
<TransactionType>D</TransactionType>
<Description>Accrued 9/04 Bonus</Description>
</Detail>
- <Detail>
<AccountNumber>50149.000</AccountNumber>
<Amount>1000.00</Amount>
<TransactionType>D</TransactionType>
<Description>Accrued 9/04 Bonus</Description>
</Detail>
- <Detail>
<AccountNumber>120149.000</AccountNumber>
<Amount>1000.00</Amount>
<TransactionType>D</TransactionType>
<Description>Accrued 9/04 Bonus</Description>
</Detail>
- <Detail>
<AccountNumber>140149.000</AccountNumber>
<Amount>2750.00</Amount>
<TransactionType>D</TransactionType>
<Description>Accrued 9/04 Bonus</Description>
</Detail>
- <Detail>
<AccountNumber>180149.000</AccountNumber>
<Amount>3193.20</Amount>
<TransactionType>D</TransactionType>
<Description>Accrued 9/04 Bonus</Description>
</Detail>
- <Detail>
<AccountNumber>848.001</AccountNumber>
<Amount>16443.20</Amount>
<TransactionType>C</TransactionType>
<Description>Accrued 9/04 Bonus</Description>
</Detail>
</JournalEntry>
</Property>
</Company>
</AccKnowledge>
</JournalEntrySchema>
There is only supposed to be the root node of AccKnowledge with the
namespace, type and customer atribute.
Here is the code snippet where I have already filled a dataset with an
Excel file using an oledbdataadapter
JournalEntrySchema je = new JournalEntrySchema();
JournalEntrySchema.AccKnowledgeDataTable tblAcc = je.AccKnowledge;
JournalEntrySchema.AccKnowledgeRow rowAcc =
tblAcc.NewAccKnowledgeRow();
rowAcc.Customer = "Prism";
rowAcc.Type = "JournalEntry";
tblAcc.AddAccKnowledgeRow(rowAcc);
JournalEntrySchema.CompanyRow crow = null;
JournalEntrySchema.PropertyRow prow = null;
JournalEntrySchema.JournalEntryRow jeRow = null;
foreach(DataRow dr in myDataSet.Tables[0].Rows)
{
if(!dr[0].ToString().Equals(prevCompany))
{
crow = je.Company.AddCompanyRow(dr[0].ToString(),rowAcc);
prow = je.Property.AddPropertyRow("",crow);
prevCompany = dr[0].ToString();
}
dtstring = dr[1].ToString();
dtstring = dtstring.Substring(0, dtstring.IndexOf(" "));
dtstring = dtstring.Substring(dtstring.LastIndexOf("/") + 1) +
"-" + dtstring.Substring(0,dtstring.IndexOf("/")) + "-" +
dtstring.Substring(dtstring.IndexOf("/") + 1,2);
jeRow = je.JournalEntry.AddJournalEntryRow(Convert.ToDateTime(dtstring),"Journal
Entry","",prow);
string acctNumber = dr[2].ToString();
acctNumber = acctNumber.Substring(0, acctNumber.Length - 3) + "."
+ acctNumber.Substring(acctNumber.Length - 3);
decimal damount = 0;
string amount = string.Empty;
string transactionType = string.Empty;
if (Convert.ToDecimal(dr[4]) > 0)
{
amount= dr[4].ToString();
if(amount.IndexOf(".") > -1)
{
if(amount.IndexOf(".").Equals(amount.Length - 2))
{
damount = Convert.ToDecimal(amount + "0");
}
else
{
damount = Convert.ToDecimal(amount);
}
}
else
{
amount = amount + ".00";
damount = Convert.ToDecimal(amount);
}
transactionType = "D";
}
else
{
amount = dr[4].ToString();
if(amount.IndexOf(".") > -1)
{
if(amount.IndexOf(".").Equals(amount.Length - 2))
{
damount = Convert.ToDecimal(amount + "0") * -1;
}
else
{
damount = Convert.ToDecimal(amount) * -1;
}
}
else
{
amount = amount + ".00";
damount = Convert.ToDecimal(amount) * -1;
}
transactionType = "C";
}
je.Detail.AddDetailRow(Convert.ToDecimal(acctNumber),damount,transactionType,dr[3].ToString(),jeRow);
}
je.WriteXml(this.fileName.Substring(0,this.fileName.LastIndexOf("."))
+ ".xml);