我有一个带有组织层次结构的 XML 结构。该<pkEntity>
元素是 org 的父 ID,并且<entityParent>
是 org 的子元素。我不知道父/子组合的深度。我需要在下面提到的状态下进行转换:
<EntityDimCollection>
<EntityDim>
<pkEntity>-9</pkEntity>
<entityParent>-7</entityParent>
<entityCode>Own_CP</entityCode>
<entityType>OT</entityType>
<essEntityCode>un.Own_CP</essEntityCode>
</EntityDim>
<EntityDim>
<pkEntity>-8</pkEntity>
<entityParent>-7</entityParent>
<entityCode>Alternatives</entityCode>
<entityType>OT</entityType>
<essEntityCode>un.Alternatives</essEntityCode>
</EntityDim>
<EntityDim>
<pkEntity>8555</pkEntity>
<entityParent>-8</entityParent>
<entityCode>Ex_BABRO</entityCode>
<entityType>CF</entityType>
<essEntityCode>un.Ex_BABRO</essEntityCode>
</EntityDim>
<EntityDim>
<pkEntity>8752</pkEntity>
<entityParent>-8</entityParent>
<entityCode>Ex_SY</entityCode>
<entityType>CF</entityType>
<essEntityCode>un.Ex_SY</essEntityCode>
</EntityDim>
<EntityDim>
<pkEntity>9731</pkEntity>
<entityParent>-8</entityParent>
<entityCode>NOR</entityCode>
<entityType>LE</entityType>
<essEntityCode>un.NOR</essEntityCode>
</EntityDim>
<EntityDim>
<pkEntity>1649940</pkEntity>
<entityParent>9731</entityParent>
<entityCode>NO</entityCode>
<entityType>CG</entityType>
<essEntityCode>un.NOR.NO</essEntityCode>
</EntityDim>
<EntityDim>
<pkEntity>1838293</pkEntity>
<entityParent>1649940</entityParent>
<entityCode>UKONORWAY</entityCode>
<entityType>CG</entityType>
<essEntityCode>un.NOR.UKONORWAY</essEntityCode>
</EntityDim>
<EntityDim>
<pkEntity>1127251</pkEntity>
<entityParent>1838293</entityParent>
<entityCode>2BUS</entityCode>
<entityType>CG</entityType>
<essEntityCode>un.NOR.2BUS</essEntityCode>
</EntityDim>
<EntityDim>
<pkEntity>1127274</pkEntity>
<entityParent>1127251</entityParent>
<entityCode>3BUS_B</entityCode>
<entityType>CG</entityType>
<essEntityCode>un.NOR.3BUS_B</essEntityCode>
</EntityDim>
<EntityDim>
<pkEntity>1988187</pkEntity>
<entityParent>1127274</entityParent>
<entityCode>4BUS_B</entityCode>
<entityType>CG</entityType>
<essEntityCode>un.NOR.4BUS_B</essEntityCode>
</EntityDim>
<EntityDim>
<pkEntity>1988188</pkEntity>
<entityParent>1988187</entityParent>
<entityCode>5ADM_B</entityCode>
<entityType>CG</entityType>
<essEntityCode>un.NOR.5ADM_B</essEntityCode>
</EntityDim>
<EntityDim>
<pkEntity>1988189</pkEntity>
<entityParent>1988187</entityParent>
<entityCode>5FVK_B</entityCode>
<entityType>CG</entityType>
<essEntityCode>un.NOR.5FVK_B</essEntityCode>
</EntityDim>
<EntityDim>
<pkEntity>1988190</pkEntity>
<entityParent>1988189</entityParent>
<entityCode>61_FVK_B</entityCode>
<entityType>CG</entityType>
<essEntityCode>un.NOR.61_FVK_B</essEntityCode>
</EntityDim>
</EntityDimCollection>
并使用 Mark Veenstra 解决方案,我得到了这样的输出
<?xml version="1.0" encoding="UTF-8"?>
<client:LMSDetails xmlns:client="http://foo/bar">
<client:ParentID>-9</client:ParentID>
<client:ChildID>-7</client:ChildID>
<client:name/>
<client:identifier>OT</client:identifier>
<client:isActive/>
<client:ParentID>-8</client:ParentID>
<client:ChildID>-7</client:ChildID>
<client:name/>
<client:identifier>OT</client:identifier>
<client:isActive/>
<client:children>
<client:ParentID>8555</client:ParentID>
<client:ChildID>-8</client:ChildID>
<client:name/>
<client:identifier>CF</client:identifier>
<client:isActive/>
</client:children>
<client:children>
<client:ParentID>8752</client:ParentID>
<client:ChildID>-8</client:ChildID>
<client:name/>
<client:identifier>CF</client:identifier>
<client:isActive/>
</client:children>
<client:children>
<client:ParentID>9731</client:ParentID>
<client:ChildID>-8</client:ChildID>
<client:name/>
<client:identifier>LE</client:identifier>
<client:isActive/>
<client:children>
<client:ParentID>1649940</client:ParentID>
<client:ChildID>9731</client:ChildID>
<client:name/>
<client:identifier>CG</client:identifier>
<client:isActive/>
<client:children>
<client:ParentID>1838293</client:ParentID>
<client:ChildID>1649940</client:ChildID>
<client:name/>
<client:identifier>CG</client:identifier>
<client:isActive/>
<client:children>
<client:ParentID>1127251</client:ParentID>
<client:ChildID>1838293</client:ChildID>
<client:name/>
<client:identifier>CG</client:identifier>
<client:isActive/>
<client:children>
<client:ParentID>1127274</client:ParentID>
<client:ChildID>1127251</client:ChildID>
<client:name/>
<client:identifier>CG</client:identifier>
<client:isActive/>
<client:children>
<client:ParentID>1988187</client:ParentID>
<client:ChildID>1127274</client:ChildID>
<client:name/>
<client:identifier>CG</client:identifier>
<client:isActive/>
<client:children>
<client:ParentID>1988188</client:ParentID>
<client:ChildID>1988187</client:ChildID>
<client:name/>
<client:identifier>CG</client:identifier>
<client:isActive/>
</client:children>
<client:children>
<client:ParentID>1988189</client:ParentID>
<client:ChildID>1988187</client:ChildID>
<client:name/>
<client:identifier>CG</client:identifier>
<client:isActive/>
<client:children>
<client:ParentID>1988190</client:ParentID>
<client:ChildID>1988189</client:ChildID>
<client:name/>
<client:identifier>CG</client:identifier>
<client:isActive/>
</client:children>
</client:children>
</client:children>
</client:children>
</client:children>
</client:children>
</client:children>
</client:children>
<client:ParentID>8555</client:ParentID>
<client:ChildID>-8</client:ChildID>
<client:name/>
<client:identifier>CF</client:identifier>
<client:isActive/>
<client:ParentID>8752</client:ParentID>
<client:ChildID>-8</client:ChildID>
<client:name/>
<client:identifier>CF</client:identifier>
<client:isActive/>
<client:ParentID>9731</client:ParentID>
<client:ChildID>-8</client:ChildID>
<client:name/>
<client:identifier>LE</client:identifier>
<client:isActive/>
<client:children>
<client:ParentID>1649940</client:ParentID>
<client:ChildID>9731</client:ChildID>
<client:name/>
<client:identifier>CG</client:identifier>
<client:isActive/>
<client:children>
<client:ParentID>1838293</client:ParentID>
<client:ChildID>1649940</client:ChildID>
<client:name/>
<client:identifier>CG</client:identifier>
<client:isActive/>
<client:children>
<client:ParentID>1127251</client:ParentID>
<client:ChildID>1838293</client:ChildID>
<client:name/>
<client:identifier>CG</client:identifier>
<client:isActive/>
<client:children>
<client:ParentID>1127274</client:ParentID>
<client:ChildID>1127251</client:ChildID>
<client:name/>
<client:identifier>CG</client:identifier>
<client:isActive/>
<client:children>
<client:ParentID>1988187</client:ParentID>
<client:ChildID>1127274</client:ChildID>
<client:name/>
<client:identifier>CG</client:identifier>
<client:isActive/>
<client:children>
<client:ParentID>1988188</client:ParentID>
<client:ChildID>1988187</client:ChildID>
<client:name/>
<client:identifier>CG</client:identifier>
<client:isActive/>
</client:children>
<client:children>
<client:ParentID>1988189</client:ParentID>
<client:ChildID>1988187</client:ChildID>
<client:name/>
<client:identifier>CG</client:identifier>
<client:isActive/>
<client:children>
<client:ParentID>1988190</client:ParentID>
<client:ChildID>1988189</client:ChildID>
<client:name/>
<client:identifier>CG</client:identifier>
<client:isActive/>
</client:children>
</client:children>
</client:children>
</client:children>
</client:children>
</client:children>
</client:children>
</client:LMSDetails>