Tech Off Thread

5 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Loading OPML into a TreeView (C#)

Back to Forum: Tech Off
  • User profile image
    Khamul

    Well, what's the best way to do this? Essentially, as you may have guessed, I'm working on a RSS Reader, and I want to store directly in OPML for compatibility and the advantage of not having to write Import/Export functions for it.

    Hope you can help.

  • User profile image
    defstream

    Your going to have to do the traditional node walking routine

     

    for example

    [code]

    private void frmMain_Load(object sender, EventArgs e)

    {

    XmlDocument xd = new XmlDocument();

    xd.LoadXml(Properties.Resources.OPML_STORE );

    trvRSS.Nodes.Add(new TreeNode("RSS Feeds"));

    LoadNode(xd.SelectNodes("//body/*"), trvRSS.Nodes[0] );

    }

     

    private void LoadNode(XmlNodeList xmlNodes, TreeNode trvParent)

    {

    foreach(XmlNode xmlNode in xmlNodes)

    {

    TreeNode trnNewNode = new TreeNode(xmlNode.Attributes["title"].Value);

    if(xmlNode.Attributes["xmlUrl"] != null)

    trnNewNode.Tag = xmlNode.Attributes["xmlUrl"].Value;

    trnNewNode.Expand();

    trvParent.Nodes.Add(trnNewNode);

    LoadNode(xmlNode.ChildNodes, trnNewNode);

    }

    }

    [/code]

  • User profile image
    Khamul

    Thanks, I'll give it a go.

  • User profile image
    Khamul

    Cool - I got that working. Now, one issue - how to serialize the TreeView into valid OPML?

  • User profile image
    defstream

    Since the treeview in itself is not serializable your going to have to create a class that extends it and sets the XmlElement of the propertys to the OPML specification element names. I found an example here http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=359047&SiteID=1


    It would be more productive to simply use the OPML as your datasource then though not as tightly integrated as serializing a treeview to and from an OPML file.

    Another possibility would be to create a serializable custom class that represents an opml file from which the treeview binds to.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.