Please Help!
I have an XML File using the DataPacket standard (am working with
Delphi/Informix poeple):
<?xml version="1.0" standalone="yes"?>
<DATAPACKET version="2">
<METADATA>
<FIELDS>
<FIELD attrname="row_id" fieldtype="i8" />
<FIELD attrname="business_unit" fieldtype="string"
SUBTYPE="VarChar" WIDTH="10" />
<FIELD attrname="business_type" fieldtype="string"
SUBTYPE="VarChar" WIDTH="12" />
<FIELD attrname="contact_company_name" fieldtype="string"
SUBTYPE="VarChar" WIDTH="100" />
</FIELDS>
</METADATA>
<ROWDATA>
<ROW row_id="0" business_unit="" business_type=""
contact_company_name="" />
</ROWDATA>
</DATAPACKET>
When I execute the following code I get the error "StartElement state
Epilog would result in an invalid XML document" when I attempt to
write the XML back to file:
Dim new_row As DataRow
Dim ds_batch As DataSet = New DataSet
ds_batch.ReadXml(global.myPath & "\batch.xml")
' Add a row
new_row = ds_batch.Tables("ROW").NewRow
Dim next_id As Integer =
ds_batch.Tables("ROW").Compute("MAX(row_id)", "")
next_id += 1
new_row.Item("row_id") = next_id
new_row.Item("business_unit") = "R"
new_row.Item("business_type") = "A"
new_row.Item("contact_company_name") = "ABC"
ds_batch.Tables("ROW").Rows.Add(new_row)
ds_batch.AcceptChanges()
Console.WriteLine(ds_batch.GetXml)
ds_batch.WriteXml(global.myPath & "\batch.xml")
The ds_batch.GetXml function returns the following XML:
<DATAPACKET version="2">
<METADATA>
<FIELDS>
<FIELD attrname="row_id" fieldtype="i8" />
<FIELD attrname="business_unit" fieldtype="string"
SUBTYPE="VarChar" WIDTH="10" />
<FIELD attrname="business_type" fieldtype="string"
SUBTYPE="VarChar" WIDTH="12" />
<FIELD attrname="contact_company_name" fieldtype="string"
SUBTYPE="VarChar" WIDTH="100" />
</FIELDS>
</METADATA>
<ROWDATA>
<ROW row_id="0" business_unit="" business_type=""
contact_company_name="" />
</ROWDATA>
</DATAPACKET>
<ROW row_id="1" business_unit="R" business_type="A"
contact_company_name="ABC" />
Obviously the document is mal-formed because the new ROW element has
been added to the end of the file.
Does anyone have a workaround for this?
Thanks in advance,
Craig