0

Currently is have this code:

        if (caseStudyImages.SelectedIndex < 0)
        {
            caseStudyImages.SelectedIndex = 0;
        }

        var item = container.Items[caseStudyImages.SelectedIndex];
        subTitle.Text = item.Title.Text;

        HtmlDocument doc = new HtmlDocument();
        doc.LoadHtml(item.NodeValue);

        doc.DocumentNode.RemoveChild(doc.DocumentNode.FirstChild);

        StringBuilder sb = new StringBuilder();
        using (StringWriter writer = new StringWriter(sb))
        {
            doc.Save(writer);
        }

        item.NodeValue = doc.ToString();       

        caseStudyImages.ItemsSource = container.Items;

caseStudyImages is a flipview on the screen that contains an image and a webview item. Container is my syndication feed item. I am trying to remove the first node from the item currently selected, as it is text I do not want, and then display it in the webview. I am binding the webview content the the item.NodeValue in a DataTemplate. My problem is on the line: item.NodeValue = doc.ToString();
I get an exception throw saying "The method or operation is not implemented". Does anyone have any suggestions?

Daniel Kelley
  • 7,579
  • 6
  • 42
  • 50
jack moseley
  • 43
  • 1
  • 11
  • Either the setter of `item.NodeValue` or `doc.ToString()` is not implemented. What does the StackTrace say where the exception occurs? – Botz3000 Feb 27 '13 at 10:25
  • hmmm.. perhaps you want `doc.OuterHtml` or `doc.InnerHtml` instead of `doc.ToString()`? – Oscar Mederos Feb 27 '13 at 10:28
  • > UICentricWin8App.exe!UICentricWin8App.HubPage.LoadText() Line 140 + 0x2c bytes C# UICentricWin8App.exe!UICentricWin8App.HubPage.caseStudyImages_SelectionChanged(object sender, Windows.UI.Xaml.Controls.SelectionChangedEventArgs e) Line 151 + 0x8 bytes C# [External Code] UICentricWin8App.exe!UICentricWin8App.HubPage.LoadImages() Line 83 + 0x49 bytes C# UICentricWin8App.exe!UICentricWin8App.HubPage.HubPage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) Line 41 + 0xc bytes C# [External Code] is what is said in call stack – jack moseley Feb 27 '13 at 10:31

1 Answers1

0

Do you have access to HtmlDocument class ? Check the ToString ovveride maybe someone left NotImplementedException there.

If you don't have access, then get the needed data from HtmlDocument that is considered to be NodeValue without using ToString(). Use String.Format

Michal Franc
  • 1,036
  • 10
  • 16
  • I checked the HtmlDocument class, and theres no override for the ToString method. Should I be using doc to get the text from or sb? – jack moseley Feb 27 '13 at 10:41
  • HtmlDocument is from HtmlAgilityPack ? If so Check this post – Michal Franc Feb 27 '13 at 10:51
  • Which post are you talking about? – jack moseley Feb 27 '13 at 10:54
  • oops no link was added in the comment : sending again http://stackoverflow.com/questions/5599012/html-agility-pack-htmldocument-show-all-html – Michal Franc Feb 27 '13 at 11:02
  • Also @Botz3000 sugested to check setter of NodeValue. What type of object is the item ? – Michal Franc Feb 27 '13 at 11:02
  • item.NodeValue is a string. It is the text content of the item that it has. I tried using doc.documentnode.outerhtml but it still gives the same error – jack moseley Feb 27 '13 at 11:43
  • Ok, check if you are able to set NodeValue by setter directly. Mayber there is some kind of a function that should be used to set this value. Baacuse as @Botz3000 sugestem there can be a problem with setter of this property. – Michal Franc Feb 27 '13 at 11:48