有关分层XML生成的设计问题 [英] Design question about generation of hierarchial xml
问题描述
输入数据采用电子表格的形式.
其中具有列H1,H2,H3,H4,H5,开始日期结束日期,高度,宽度,阶段和等级
我想生成hirerrichial xml
H1
H2
H3
H4
H5
这意味着H4是H5的父级,H3是H4的父级,依此类推……
xml的格式为
< SetEquipment H1Id =<来自excel的变量H1 type ='H1'>
<地址高度=<可变高度> 宽度=<可变宽度>> />
< SetEquipment H2Id =<来自excel的变量H2> 类型='H2'>
< SetParentEquipment ParentEquipmentId =<来自excel的变量H1 type ='H1'>
< ParentLinkRange Start =< Excel的可变开始日期> End =<< Excel的可变结束日期> />
</SetParentEquipment>
<地址高度=<距excel的可变高度> width =<来自excel的可变宽度> />
</SetEquipment>
< SetEquipment H3Id =<来自excel的变量H3> 类型='H2'>
< SetParentEquipment ParentEquipmentId =<来自excel的变量H2 type ='H2'>
< ParentLinkRange Start =< Excel的可变开始日期> End =<< Excel的可变结束日期> />
</SetParentEquipment>
</SetEquipment>
< SetEquipment H4Id =<来自excel的变量H4> 类型='H4'>
< SetParentEquipment ParentEquipmentId =<来自excel的变量H3> type ='H3'>
< ParentLinkRange Start =< Excel的可变开始日期> End =<< Excel的可变结束日期> />
</SetParentEquipment>
< TransformerAttributes RatingKVA =<来自excel的变量评级> />
</SetEquipment>
< SetEquipment H5Id =<来自excel的变量H5> 类型='H5'>
< SetParentEquipment ParentEquipmentId =<来自excel的变量H4> type ='H4'>
< ParentLinkRange Start =< Excel的可变开始日期> End =<< Excel的可变结束日期> />
</SetParentEquipment>
< SPAttributes NumberOfPhases =< Excel的可变阶段> />
</SetEquipment>
在Visual Studio 2012中
我正计划将电子表格中的数据导入数据集中
创建以下类
SetEquipment
SetParentEquipment
地址
TransformerAttributes
SPAttributes
使用名称空间system.linq生成xml
问题:
如果有人对更好的设计有任何建议,可以做到这一点,我非常感兴趣
谢谢
您好sairam,
在提供的演示文件中,似乎五个元素(H1〜h5)处于同一级别,它们没有物理层次结构,但是具有逻辑层次.为此,我认为您需要使用 System.Linq.XML 构造输出格式,因为System.Linq.XML命名空间无法解析层次结构逻辑.
或者您可以通过在DataSet中设置关系来创建物理层次结构格式的输出XML文件,有关详细信息,您可以检查以下链接:
http://stackoverflow.com/a/15166373
此致.
Input data is in the form of spreadsheet.
Which has colums H1, H2, H3 H4, H5, startdate, enddate, height, width, phases and rating
I want to generate hirerichial xml
H1
H2
H3
H4
H5
That means H4 is parent of H5, H3 is parent of H4 and so on......
A format of an xml will be
<SetEquipment H1Id=<variable H1 from excel> type='H1'>
<Address height=<variable height> width =<variable width> />
<SetEquipment H2Id=<Variable H2 from excel> type ='H2'>
<SetParentEquipment ParentEquipmentId=<variable H1 from excel> type='H1'>
<ParentLinkRange Start=<Variable startdate from excel> End=<Variable enddate from excel> />
</SetParentEquipment>
<Address height=<variable height from excel> width=<variable width from excel> />
</SetEquipment>
<SetEquipment H3Id=<Variable H3 from excel> type ='H2'>
<SetParentEquipment ParentEquipmentId=<variable H2 from excel> type='H2'>
<ParentLinkRange Start=<Variable startdate from excel> End=<Variable enddate from excel> />
</SetParentEquipment>
</SetEquipment>
<SetEquipment H4Id=<Variable H4 from excel> type ='H4'>
<SetParentEquipment ParentEquipmentId=<variable H3 from excel> type='H3'>
<ParentLinkRange Start=<Variable startdate from excel> End=<Variable enddate from excel> />
</SetParentEquipment>
<TransformerAttributes RatingKVA=<Variable rating from excel> />
</SetEquipment>
<SetEquipment H5Id=<Variable H5 from excel> type ='H5'>
<SetParentEquipment ParentEquipmentId=<variable H4 from excel> type='H4'>
<ParentLinkRange Start=<Variable startdate from excel> End=<Variable enddate from excel> />
</SetParentEquipment>
<SPAttributes NumberOfPhases=<Variable phases from excel> />
</SetEquipment>
In Visual studio 2012
I am planning to get a data from spreadsheet into a dataset
Create the following classes
SetEquipment
SetParentEquipment
Address
TransformerAttributes
SPAttributes
using the namespace system.linq to generate xml
Question:
If anyone has any suggestion for better design this can be done I am very much interested
Thanks
Hello sairam,
With your provided demo file, it seems that they five elements(H1~h5) are in the same level, which does not have a physical hierarchy but a logic one. For this, I think you need to use the System.Linq.XML to construct the output format since the hierarchy logic(you want) cannot be parsed by the System.Linq.XML namespace.
Or you could create a physical hierarchy format output XML file by setting the relationship in your DataSet, for details, you could check this link:
http://stackoverflow.com/a/15166373
Regards.
这篇关于有关分层XML生成的设计问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!