J
jk
I'm having trouble converting a datatable into xml, with resonse.write
to aspx. I'm basically converting vb code that saved a recordset into a
stream into c#, but the format is wrong. I've tried using streams,
datadoc, xmlreader, etc with no success. I need to convert it directly
to a string or via a stream, but not in a file. Here's some sample
code that gives me the bad format. I'll post the good format below that
give me rowsets rather than tables. thanks for any help!!
StringWriter sw = new StringWriter();
dt.DataSet.WriteXml(sw, XmlWriteMode.WriteSchema);
string s = sw.ToString();
Response.Write("<?xml version='1.0' ?>");
Response.Write(s);
<!-- give me this: /-->
<?xml version='1.0' ?>
<NewDataSet>
<xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:attribute name="VAR_VALUE" type="xs:string" />
<xs:attribute name="VAR_KEY" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<Table VAR_VALUE="LSUS" VAR_KEY="DIVISION" />
<Table VAR_VALUE="DB2T" VAR_KEY="DB2DSN" />
<Table VAR_VALUE="TRUE" VAR_KEY="PRODPROF" />
</NewDataSet>
<!-- I need this: /-->
<?xml version='1.0' ?>
<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
xmlns:rs='urn:schemas-microsoft-com:rowset'
xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
<s:ElementType name='row' content='eltOnly'>
<s:AttributeType name='VAR_VALUE' rs:number='1'
rs:nullable='true'
rs:writeunknown='true'>
<s:datatype dt:type='string' rs:dbtype='str'
dt:maxLength='200'/>
</s:AttributeType>
<s:AttributeType name='VAR_KEY' rs:number='2'
rs:writeunknown='true'>
<s:datatype dt:type='string' rs:dbtype='str'
dt:maxLength='10'
rs:maybenull='false'/>
</s:AttributeType>
<s:extends type='rs:rowbase'/>
</s:ElementType>
</s:Schema>
<rs:data>
<z:row VAR_VALUE='LSUS' VAR_KEY='DIVISION'/>
<z:row VAR_VALUE='DB2P' VAR_KEY='DB2DSN'/>
<z:row VAR_VALUE='TRUE' VAR_KEY='PRODPROF'/>
</rs:data>
</xml>
to aspx. I'm basically converting vb code that saved a recordset into a
stream into c#, but the format is wrong. I've tried using streams,
datadoc, xmlreader, etc with no success. I need to convert it directly
to a string or via a stream, but not in a file. Here's some sample
code that gives me the bad format. I'll post the good format below that
give me rowsets rather than tables. thanks for any help!!
StringWriter sw = new StringWriter();
dt.DataSet.WriteXml(sw, XmlWriteMode.WriteSchema);
string s = sw.ToString();
Response.Write("<?xml version='1.0' ?>");
Response.Write(s);
<!-- give me this: /-->
<?xml version='1.0' ?>
<NewDataSet>
<xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:attribute name="VAR_VALUE" type="xs:string" />
<xs:attribute name="VAR_KEY" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<Table VAR_VALUE="LSUS" VAR_KEY="DIVISION" />
<Table VAR_VALUE="DB2T" VAR_KEY="DB2DSN" />
<Table VAR_VALUE="TRUE" VAR_KEY="PRODPROF" />
</NewDataSet>
<!-- I need this: /-->
<?xml version='1.0' ?>
<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
xmlns:rs='urn:schemas-microsoft-com:rowset'
xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
<s:ElementType name='row' content='eltOnly'>
<s:AttributeType name='VAR_VALUE' rs:number='1'
rs:nullable='true'
rs:writeunknown='true'>
<s:datatype dt:type='string' rs:dbtype='str'
dt:maxLength='200'/>
</s:AttributeType>
<s:AttributeType name='VAR_KEY' rs:number='2'
rs:writeunknown='true'>
<s:datatype dt:type='string' rs:dbtype='str'
dt:maxLength='10'
rs:maybenull='false'/>
</s:AttributeType>
<s:extends type='rs:rowbase'/>
</s:ElementType>
</s:Schema>
<rs:data>
<z:row VAR_VALUE='LSUS' VAR_KEY='DIVISION'/>
<z:row VAR_VALUE='DB2P' VAR_KEY='DB2DSN'/>
<z:row VAR_VALUE='TRUE' VAR_KEY='PRODPROF'/>
</rs:data>
</xml>