好日子,我需要將所有ComposedBlock
標記移動到TextBlock
的最後一個位置,示例XML位於下方。將XML元素移動到特定位置
這是XML輸入:
<parent>
<ComposedBlock ID="P1_CB0000001" HPOS="6278" VPOS="1670" WIDTH="3610" HEIGHT="2727">
<GraphicalElement ID="P1_CB0000001_SUB" HPOS="6278" VPOS="1670" WIDTH="3610" HEIGHT="2727" />
</ComposedBlock>
<ComposedBlock ID="P1_CB0000002" HPOS="653" VPOS="1728" WIDTH="1689" HEIGHT="730">
<GraphicalElement ID="P1_CB0000002_SUB" HPOS="653" VPOS="1728" WIDTH="1689" HEIGHT="730" />
</ComposedBlock>
<TextBlock ID="P1_TB0000006" HPOS="2539" VPOS="1675" WIDTH="1200" HEIGHT="120" LANG="en" STYLEREFS="PAR_JUSTIFIED">
<TextLine ID="P1_TL0000028" HPOS="2539" VPOS="1675" WIDTH="1200" HEIGHT="120">
<String ID="P1_ST0000165" HPOS="2539" VPOS="1680" WIDTH="63" HEIGHT="86" CONTENT="ijt" />
<SP ID="P1_SP0000156" HPOS="2602" VPOS="1766" />
</TextLine>
</TextBlock>
<TextBlock ID="P1_TB0000011" HPOS="4406" VPOS="5170" WIDTH="1724" HEIGHT="1003" LANG="en" STYLEREFS="PAR_JUSTIFIED">
<TextLine ID="P1_TL0000083" HPOS="4411" VPOS="5170" WIDTH="1714" HEIGHT="120">
<String ID="P1_ST0000532" HPOS="4411" VPOS="5170" WIDTH="346" HEIGHT="91" CONTENT="Change" />
<SP ID="P1_SP0000513" HPOS="4757" VPOS="5261" />
<String ID="P1_ST0000533" HPOS="4776" VPOS="5198" WIDTH="230" HEIGHT="63" CONTENT="yo0ur" />
<SP ID="P1_SP0000514" HPOS="5006" VPOS="5261" />
</TextLine>
</TextBlock>
</parent>
,這是所需的輸出:
<parent>
<TextBlock ID="P1_TB0000006" HPOS="2539" VPOS="1675" WIDTH="1200" HEIGHT="120" LANG="en" STYLEREFS="PAR_JUSTIFIED">
<TextLine ID="P1_TL0000028" HPOS="2539" VPOS="1675" WIDTH="1200" HEIGHT="120">
<String ID="P1_ST0000165" HPOS="2539" VPOS="1680" WIDTH="63" HEIGHT="86" CONTENT="ijt" />
<SP ID="P1_SP0000156" HPOS="2602" VPOS="1766" />
</TextLine>
</TextBlock>
<TextBlock ID="P1_TB0000011" HPOS="4406" VPOS="5170" WIDTH="1724" HEIGHT="1003" LANG="en" STYLEREFS="PAR_JUSTIFIED">
<TextLine ID="P1_TL0000083" HPOS="4411" VPOS="5170" WIDTH="1714" HEIGHT="120">
<String ID="P1_ST0000532" HPOS="4411" VPOS="5170" WIDTH="346" HEIGHT="91" CONTENT="Change" />
<SP ID="P1_SP0000513" HPOS="4757" VPOS="5261" />
<String ID="P1_ST0000533" HPOS="4776" VPOS="5198" WIDTH="230" HEIGHT="63" CONTENT="yo0ur" />
<SP ID="P1_SP0000514" HPOS="5006" VPOS="5261" />
</TextLine>
</TextBlock>
<ComposedBlock ID="P1_CB0000001" HPOS="6278" VPOS="1670" WIDTH="3610" HEIGHT="2727">
<GraphicalElement ID="P1_CB0000001_SUB" HPOS="6278" VPOS="1670" WIDTH="3610" HEIGHT="2727" />
</ComposedBlock>
<ComposedBlock ID="P1_CB0000002" HPOS="653" VPOS="1728" WIDTH="1689" HEIGHT="730">
<GraphicalElement ID="P1_CB0000002_SUB" HPOS="653" VPOS="1728" WIDTH="1689" HEIGHT="730" />
</ComposedBlock>
</parent>
這裏是我的代碼:
XElement doc = XElement.Parse(reader);
IEnumerable<XElement> wd =
from el in doc.Descendants("ComposedBlock").ToList()
select el;
foreach (XElement el in wd)
{
//what do i need to do here?
}
爲什麼不調用Remove而不是ReplaceW ith(null)? – CSharpie
我沒有想到它。 – jdweng