Exemplo n.º 1
0
        // CDATA
        // Should escape all CDATA content and remove the CDATA element
        private void ProcessDescendantCdataElements(XElement parentElement)
        {
            // Take them one at a time in case we erase one during the processing
            XCData cdata = parentElement.DescendantNodes().OfType <XCData>().FirstOrDefault();

            while (cdata != null)
            {
                cdata.ReplaceWith(new XText(cdata.Value.Trim()));
                cdata = parentElement.DescendantNodes().OfType <XCData>().FirstOrDefault();
            }
        }
        static void Main(string[] args)
        {
            XDocument doc = XDocument.Load(FILENAME);

            foreach (XElement node in doc.Descendants("Node"))
            {
                XElement songs    = node.Descendants("songs").FirstOrDefault();
                XCData   child    = (XCData)songs.FirstNode;
                string   childStr = child.ToString();
                childStr = childStr.Replace("Some text here", "Some text there");
                child.ReplaceWith(childStr);
            }
        }