score:1

Accepted answer

Select page which you need

XDocument xdoc = XDocument.Load("Test.xml");
int pageId = 2;
var page = xdoc.Descendants("Page")
                .FirstOrDefault(p => (int)p.Element("Id") == pageId);

And then add content to this page element (if any):

if (page != null)
{
    // add to Hotspots element
    page.Element("Hotspots")
        .Add(new XElement("Hotspot",
                 new XElement("X", x),
                 new XElement("Y", y),
                 new XElement("Shape", "Circle"),
                 new XElement("TargetId", nNodeID)));

    xdoc.Save("Test.xml");
}

Your code adds new Hotspot element to page, instead of adding content to existing Hotspots element.


Related Articles