DataTable.WriteXML 和子节点
我有以下代码片段:
var dataSet = new DataSet("Data");
var table = GetCustomerTable();
var orgTable = GetOrganizationTable();
dataSet.Tables.Add(table);
dataSet.Tables.Add(orgTable);
var relation = new DataRelation("CustomerMembership", dataSet.Tables["Customers"].Columns["CustomerId"], dataSet.Tables["Organizations"].Columns["CustomerId"])
{Nested = true};
dataSet.Relations.Add(relation);
dataSet.WriteXml(@"C:\MyFeed.xml");
这给了我以下结果:
<Customers>
<CustomerId>272408857</CustomerId>
<snip>
<Organizations>
<OrganizationName>Org1</OrganizationName>
</Organizations>
<Organizations>
<OrganizationName>Org2</OrganizationName>
</Organizations>
</Customers>
我正在寻找的是这样的:
<Customers>
<CustomerId>272408857</CustomerId>
<snip>
<Organizations>
<OrganizationName>Org1</OrganizationName>
<OrganizationName>Org2</OrganizationName>
</Organizations>
</Customers>
关于如何将 OrganizationName
嵌套在一个 中的任何想法组织
节点;而不是有 2 个节点,每个节点一个值?
I've got the following snippet of code:
var dataSet = new DataSet("Data");
var table = GetCustomerTable();
var orgTable = GetOrganizationTable();
dataSet.Tables.Add(table);
dataSet.Tables.Add(orgTable);
var relation = new DataRelation("CustomerMembership", dataSet.Tables["Customers"].Columns["CustomerId"], dataSet.Tables["Organizations"].Columns["CustomerId"])
{Nested = true};
dataSet.Relations.Add(relation);
dataSet.WriteXml(@"C:\MyFeed.xml");
Which gives me the following result:
<Customers>
<CustomerId>272408857</CustomerId>
<snip>
<Organizations>
<OrganizationName>Org1</OrganizationName>
</Organizations>
<Organizations>
<OrganizationName>Org2</OrganizationName>
</Organizations>
</Customers>
What I'm looking for is something like this:
<Customers>
<CustomerId>272408857</CustomerId>
<snip>
<Organizations>
<OrganizationName>Org1</OrganizationName>
<OrganizationName>Org2</OrganizationName>
</Organizations>
</Customers>
Any ideas on how I can get OrganizationName
nested inside of one Organization
node; instead of having 2 nodes with one value each?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将其添加到您的代码中将输出以下内容:
这并不完全是您所需要的,但我认为您无法使用 .net 工具收集表标记中联接的子节点。您可能必须自己转换 xml。
您还可以将 DataTable 重命名为“Organization”,这样您将拥有一个
Organization
元素列表(尽管仍然缺少父Organizations
元素)。你怎么认为?
Adding this to your code will output the following:
It is not exactly what you need, but I think you cannot collect the child nodes of a join in a table-tag with .net tools. You will probably have to transform the xml by yourself.
You could also rename your DataTable to "Organization" such that you will have a list of
Organization
Elements (still lacking a parentOrganizations
element though).What do you think?