希望你做得很好我有一个场景,我从一个扁平结构的服务中得到一个结果集这个结果集有经理,他的项目和每个项目中的活动
我想把这个平面结构转换成 xml
Grouped by Manager
Grouped by Project
Activities in that Project
这是我拥有的xml
<Results>
<Result>
<ActivityId>101</ActivityId>
<ActivityName>T1</ActivityName>
<ProjectId>1001</ProjectId>
<ProjectName>Prj1</ProjectName>
<Description>some desc</Description>
<manager>jcooper</manager>
</Result>
<Result>
<ActivityId>102</ActivityId>
<ActivityName>T2</ActivityName>
<ProjectId>1002</ProjectId>
<ProjectName>Prj2</ProjectName>
<Description>some desc</Description>
<manager>jstein</manager>
</Result>
<Result>
<ActivityId>103</ActivityId>
<ActivityName>T3</ActivityName>
<ProjectId>1001</ProjectId>
<ProjectName>Prj1</ProjectName>
<Description>some desc</Description>
<manager>jcooper</manager>
</Result>
<Result>
<ActivityId>104</ActivityId>
<ActivityName>T4</ActivityName>
<ProjectId>1002</ProjectId>
<ProjectName>Prj2</ProjectName>
<Description>some desc</Description>
<manager>jcooper</manager>
</Result>
<Result>
<ActivityId>105</ActivityId>
<ActivityName>T5</ActivityName>
<ProjectId>1002</ProjectId>
<ProjectName>Prj2</ProjectName>
<Description>some desc</Description>
<manager>jstein</manager>
</Result>
</Results>
在此,经理 jcooper 有 Prj1{有活动 T1,T3} 和 Prj2{有活动 T4} 经理 jstein 有 Prj1(有活动 T2)和 prj2{有活动 T5}
这是我正在尝试的格式
Manager
List of Prjs
List of Activities in corresponding Project
<Results>
<ManagerWiseResult>
<Manager>jcooper</Manager>
<Project>
<ProjectId>1001</ProjectId>
<ProjectName>Prj1</ProjectName>
<Activities> <!--Activities in Project1 -->
<IndActivity>
<ActivityId>101</ActivityId>
<ActivityName>T1</ActivityName>
</IndActivity>
<IndActivity>
<ActivityId>103</ActivityId>
<ActivityName>T2</ActivityName>
</IndActivity>
</Activities>
</Project>
<Project>
<ProjectId>1002</ProjectId>
<ProjectName>Prj2</ProjectName>
<Activities>
<IndActivity>
<ActivityId>104</ActivityId>
<ActivityName>T4</ActivityName>
</IndActivity>
</Activities>
</Project>
</ManagerWiseResult>
<ManagerWiseResult>
<Project>
<ProjectId>1001</ProjectId>
<ProjectName>Prj1</ProjectName>
<Activities>
<IndActivity>
<ActivityId>102</ActivityId>
<ActivityName>T2</ActivityName>
</IndActivity>
</Activities>
</Project>
<Project>
<ProjectId>1002</ProjectId>
<ProjectName>Prj2</ProjectName>
<Activities>
<IndActivity>
<ActivityId>105</ActivityId>
<ActivityName>T5</ActivityName>
</IndActivity>
</Activities>
</Project>
</ManagerWiseResult>
</Results>
我正在尝试找出解决方案,但无法解决。专家,请您在这方面帮助我。
提前致谢, 拉维