从DataSet控制XML序列化 - “TableName节点”上的属性 [英] Control XML Serialization from DataSet -- Attributes on "TableName node"

查看:105
本文介绍了从DataSet控制XML序列化 - “TableName节点”上的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望我选择了正确的论坛。

我有一个数据集对象,其中有一个表来自一个常见的自定义组件的GetDS方法。我需要将XML传递给另一个进程(分块为字节数组)。我已经完成了所有工作,但XML缺少了一些消费过程所期望的属性。

我使用GetXML方法序列化为XML,如下所示:


< pre lang = x-xml><?xml version =" 1.0"独立= QUOT;是" ?>
< FooUpload>
< Foo>
< FooMasterID> 483< / FooMasterID>
< Country> 27< / Country>
< PaymentCode> ANN< / PaymentCode>
<金额> 132< / Amount>
< PaidDate> 2012-12-31 00:00:00< / PaidDate>
< PaidBy> FooServices< / PaidBy>
< / Foo>
< / FooUpload>

调用过程需要

<?xml version =" 1.0"编码= QUOT; UTF-8英寸独立= QUOT;是" ?> 
< FooUpload ClientCode =" FOOO"的RecordCount = QUOT 1 QUOT; CREATEDATE = QUOT; 2008-12-09T15:02:18.920" CREATEUSER = QUOT; VALLI">
< Foo>
< FooMasterID> 483< / FooMasterID>
< Country> 27< / Country>
< PaymentCode> ANN< / PaymentCode>
<金额> 132< / Amount>
< PaidDate> 2012-12-31 00:00:00< / PaidDate>
< PaidBy> FooServices< / PaidBy>
< / Foo>
< / FooUpload>

注意FooUpload元素的属性。此节点是DataSet中DataTable的名称。

我搜索了如何控制XMLSerializer并查找自定义对象的大量示例。我甚至找到了将列映射设置为MappingType.Attribute的示例,它是关闭的(不是列"节点")。

我觉得我很亲密,如果我找不到更优雅的解决方案我将不得不创建一个像循环和吐出更改的字符串加上其余XML的黑客。

提前谢谢(手指交叉)!



解决方案

Hi

由于所需的更改似乎很少,您可以尝试获取xml使用GetXml并使用Linq将所需的任何属性添加到Xml并将其发送到需要的进程。这听起来怎么样?


Hope I chose the correct forum.

I have a dataset object with one table that comes to me from a common custom component's GetDS method. I need to pass XML to another process (chunked as byte array). I have it all working but the XML is missing some attributes that the consuming process expects.

I use the GetXML method to serialize to XML that looks like the following:

<?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 expects

<?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>

Note the attributes on the FooUpload element. This node is the name of the DataTable in the DataSet.

I have searched for how to control the XMLSerializer and find lots of examples for custom objects. I even found examples of setting the column mapping to be MappingType.Attribute which is close (not a column "node").

I feel that I am close and if I do not find a more elegant solution I will have to create a hack like looping and spitting out changed string plus rest of the XML.

Thanks in advance (fingers crossed)!




 

解决方案

Hi

Since the change required seems to be minimal you can try getting the xml by using GetXml and add whatever attributes you want using Linq to Xml and send it to the process that requires. How does that sound?


这篇关于从DataSet控制XML序列化 - “TableName节点”上的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆