Linq To XML : Move Element Failed?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have an xml document as follows:
<pre class="prettyprint <WindowSettings>
<WindowPositions name="ContainerWindow_1107900644" x="1580.000000" y="504.000000" width="323.000000" height="420.000000" />
<WindowPositions name="CharacterSheet" x="1411.000000" y="276.000000" />
<WindowPositions name="CharacterAbilities" x="1057.000000" y="97.000000" />
<WindowPositions name="SkillsWindow" x="1074.000000" y="34.000000" />
<WindowPositions name="MacroWindow" x="27.000000" y="403.000000" />
<WindowPositions name="StatusWindow" x="20.000000" y="14.000000" />
<WindowPositions name="MenuBarWindow" x="699.000000" y="960.000000" />
<WindowPositions name="PetWindow" x="14.000000" y="206.000000" />
<WindowPositions name="TargetWindow" x="814.000000" y="0.000000" />
<WindowPositions name="ActionsWindow" x="1148.000000" y="429.000000" />
<WindowPositions name="MapWindow" x="1162.000000" y="13.000000" width="711.000000" height="672.000000" />
<WindowPositions name="RadarWindow" x="1627.000000" y="22.000000" />
<WindowPositions name="Hotbar1" x="10.000000" y="970.000000" width="620.000000" height="50.000000" />
<WindowPositions name="PaperdollWindow34158645" x="842.000000" y="144.000000" />
<WindowPositions name="RUNEBOOK_GUMP" x="1033.000000" y="94.000000" />
<WindowPositions name="ObjectHandleToggleWindow" x="884.000000" y="10.000000" />
<WindowPositions name="Hotbar2" x="1269.000000" y="965.000000" width="620.000000" height="50.000000" />
<WindowPositions name="CustomSetting___AlwaysShowCoordsOnAtlas" x="-9999.000000" y="1.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="CustomSetting___ShowFacetInfo" x="-9999.000000" y="1.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="CustomSetting___ShowPlayerHouses" x="-9999.000000" y="1.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="CustomSetting___UseItemPropertiesEvaluator" x="-9999.000000" y="1.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="CustomSetting___ItemPropertiesSpecialTexts_DefaultTitleLabelFont" x="1566677.000000" y="1783751.000000" width="1925476.000000" height="1833588.000000" />
<WindowPositions name="CustomSetting___ItemPropertiesSpecialTexts_DefaultTitleLabelFont_1" x="1665646.000000" y="14968.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="CustomSetting___ItemPropertiesSpecialTexts_DefaultTitleLabelFont_2" x="-9999.000000" y="-9999.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="CustomSetting___ItemPropertiesSpecialTexts_DefaultTitleLabelFont_3" x="-9999.000000" y="-9999.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="CustomSetting___ItemPropertiesSpecialTexts_DefaultTitleLabelFont_4" x="-9999.000000" y="-9999.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="CustomSetting___ItemPropertiesSpecialTexts_DefaultLabelFont" x="1566677.000000" y="1684164.000000" width="1784545.000000" height="1665652.000000" />
<WindowPositions name="CustomSetting___ItemPropertiesSpecialTexts_DefaultLabelFont_1" x="14968.000000" y="-9999.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="CustomSetting___ItemPropertiesSpecialTexts_DefaultLabelFont_2" x="-9999.000000" y="-9999.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="CustomSetting___ItemPropertiesSpecialTexts_DefaultLabelFont_3" x="-9999.000000" y="-9999.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="CustomSetting___ItemPropertiesSpecialTexts_DefaultLabelFont_4" x="-9999.000000" y="-9999.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="CustomSetting___ItemPropertiesSpecialTexts_ItemPropertiesColoring" x="-9999.000000" y="0.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="CustomSetting___OverheadSpellTransformType" x="1.000000" y="-9999.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="CustomSetting___RememberedCustomUI" x="1849283.000000" y="1880816.000000" width="1811167.000000" height="1814760.000000" />
<WindowPositions name="CustomSetting___RememberedCustomUI_1" x="1651427.000000" y="-9999.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="CustomSetting___RememberedCustomUI_2" x="-9999.000000" y="-9999.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="CustomSetting___RememberedCustomUI_3" x="-9999.000000" y="-9999.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="CustomSetting___RememberedCustomUI_4" x="-9999.000000" y="-9999.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="PartyHealthBar_2" x="12.000000" y="218.000000" />
<WindowPositions name="PartyHealthBar_1" x="11.000000" y="134.000000" />
<WindowPositions name="CustomSetting___QuickDetailsWindowDetails_RealTime" x="-9999.000000" y="1.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="CustomSetting___QuickDetailsWindowDetails_Weight" x="-9999.000000" y="1.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="CustomSetting___QuickDetailsWindowDetails_Gold" x="-9999.000000" y="1.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="Hotbar3" x="1331.000000" y="409.000000" width="570.000000" height="50.000000" />
<WindowPositions name="ContainerWindow_1100777801" x="1226.000000" y="521.000000" width="323.000000" height="313.000000" />
<WindowPositions name="ContainerWindow_1116205924" x="1232.000000" y="586.000000" width="323.000000" height="313.000000" />
<WindowPositions name="ContainerWindow_1116205927" x="1153.000000" y="415.000000" width="323.000000" height="313.000000" />
<WindowPositions name="ContainerWindow_1116205925" x="1590.000000" y="34.000000" width="323.000000" height="313.000000" />
<WindowPositions name="CustomSetting___QuickDetailsWindowDetails_Followers" x="-9999.000000" y="1.000000" width="-9999.000000" height="-9999.000000" />
<WindowPositions name="SkillsTrackerWindow" x="1890.000000" y="504.000000" />
<WindowPositions name="ContainerWindow_1116205923" x="1610.000000" y="534.000000" width="323.000000" height="313.000000" />
</WindowSettings>[/code]
I want to move all of the WindowPositions elements containing customer settings to the end WindowSettings. I use the following code, but the resulting XML file shows only that the elements were removed, but not moved.
<pre class="prettyprint lang-vb Private Sub MoveCustomSettings()
Moves All Custom Settings To End of WindowSettingss Node
Dim CustomSettings = From cs In doc...<WindowSettings>.<WindowPositions>
Where cs.@name Like "CustomSetting___*"
Select cs

CustomSettings.Remove()

doc...<WindowSettings>.<WindowPositions>.Last.Add(CustomSettings)

ToolStripStatusLabel1.Text = "Custom Settings Successfully Moved."

End Sub[/code]
I found similar code on many sites, but I am guessing it has to do with attributes since none of the other code I saw had attributes in the elements. What am I doing wrong?

View the full article
 
Back
Top