組織階層を持つ XML 構造があります。要素は orgの<pkEntity>
親 ID であり、org<entityParent>
の子です。親子コンビの奥深さがわからない。以下の状態に変換する必要があります。
<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>