This project has moved and is read-only. For the latest updates, please go here.
1
Vote

ReplaceChild not working in WinRT version

description

I'm trying to parse HTML and convert it to Markdown in a WinRT app, and I've got the following code
            foreach (var x in doc.DocumentNode.SelectNodes("//strong"))
            {
                x.ParentNode.ReplaceChild(
                        HtmlAgilityPack.HtmlNode.CreateNode("**" + x.InnerHtml + "**"),
                x);
            }
This works in .NET4 in an MVC project. Obviously I had to change it as SelectNodes is not available in WinRT, so I replaced that with Descendants
            foreach (var x in doc.DocumentNode.Descendants("//strong"))
            {
                x.ParentNode.ReplaceChild(
                        HtmlAgilityPack.HtmlNode.CreateNode("**" + x.InnerHtml + "**"),
                x);
            }
I've also tried this
            var query = doc.DocumentNode.Descendants("strong");
            foreach (var item in query.ToList())
            {
                var newNodeStr = "**test**";
                var newNode = HtmlNode.CreateNode(newNodeStr);
                item.ParentNode.ReplaceChild(newNode, item);
            }
Neither of these work. It seems ReplaceChild in the WinRT build doesn't do what it is supposed to?

comments

roryok wrote Dec 15, 2014 at 11:16 AM

Someone on StackOverflow pointed out that Descendants does not handle XPath, so the set returned is empty. That was my issue. You can close this!