Managing XML Serialization from a DataSet - Attributes in the TableName Element

I hope I have chosen the right forum.

I have a dataset object with a single table that comes to me from a common custom GetDS method. I need to pass the XML to another process (chunked as byte array). Everything works for me, but in XML there are no some attributes that expect consumption processes.

I create a dataset object and can control the name of the TableName (root element) and row as follows:

da.Fill(ds, "Foo")
ds.DataSetName = "FooUpload"

I am using the GetXML method to serialize to XML, which is as follows:

<?xml version="1.0" standalone="yes" ?> 
<FooUpload>
  <Foo>
  <FooMasterID>483</FooMasterID> 
  <Country>27</Country> 
  <PaymentCode>ANN</PaymentCode> 
  <Amount>132</Amount> 
  <PaidDate>2012-12-31 00:00:00</PaidDate> 
  <PaidBy>FooServices</PaidBy> 
  </Foo>
</FooUpload>

The calling process is waiting

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
<FooUpload **ClientCode="FOOO" RecordCount="1" CreateDate="2008-12-09T15:02:18.920" CreateUser="valli"**>
  <Foo>
  <FooMasterID>483</FooMasterID> 
  <Country>27</Country> 
  <PaymentCode>ANN</PaymentCode> 
  <Amount>132</Amount> 
  <PaidDate>2012-12-31 00:00:00</PaidDate> 
  <PaidBy>FooServices</PaidBy> 
  </Foo>
</FooUpload>

Pay attention to the attributes of the FooUpload element. This node is the name of the DataTable in the DataSet.

, XMLSerializer . MappingType.Attribute, , , TableName .

, , , , XML.

( )!

+3
2

GetXML XmlDocument . :

 XmlDocument xdoc = new XmlDocument();
 xdoc.LoadXml(ds.GetXml());
 XmlAttribute attr=xdoc.CreateAttribute("ClientCode");
 attr.Value = "FOOOO";
 xdoc.DocumentElement.Attributes.Append(attr);

xdoc , :

 XmlTextWriter xw = new XmlTextWriter(new MemoryStream(),Encoding.UTF8);
 xdoc.Save(xw);
 xw.BaseStream.Position = 0;
 StreamReader sr = new StreamReader(xw.BaseStream);
 string result = sr.ReadToEnd();
0

, , .

0

Source: https://habr.com/ru/post/1726363/


All Articles