inserting a node

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Hopper

    inserting a node

    I have an rss document (below) and I need to insert a new item after the last
    existing item. Can someone suggest an approach/strategy? I don't even really
    know where to begin.

    Thanks,


    <?xml version="1.0" ?>
    - <rss version="2.0">
    - <channel>
    <title>Edwin Hicks van Deusen (2003 - 2004)</title>

    <link>http://www./resultsbycasenu mber.asp?type=3 &year=2005&numb er=17284&myPage =searchbycasenu mber.asp</link>
    <description>Ed win Hicks van Deusen (2003 - 2004)</description>
    <pubDate>10/26/2005 1:39:00 PM</pubDate>
    <lastBuildDate> 8/10/2006 1:12:12 PM</lastBuildDate>
    - <item>
    <title>Item</title>
    <guid isPermaLink="fa lse">f824721b-ba52-429e-a6ad-5b7a5979db51</guid>
    <description>DE CISION: Attorney suspended for a period of 2 years with the
    2nd year stayed on conditions. See opinion at 20063821</description>
    <pubDate>8/9/2006 9:11:00 AM</pubDate>
    </item>
    </channel>
    </rss>

  • Martin Honnen

    #2
    Re: inserting a node



    John Hopper wrote:
    I have an rss document (below) and I need to insert a new item after the last
    existing item. Can someone suggest an approach/strategy?
    Well the DOM with XmlDocument is one way in .NET to manipulate an XML
    document e.g. C# code
    XmlDocument rssFeed = new XmlDocument();
    rssFeed.Load(@" file.xml");
    XmlElement newItem = rssFeed.CreateE lement("item");
    XmlElement description = rssFeed.CreateE lement("descrip tion");
    description.Inn erText = "descriptio n goes here";
    newItem.AppendC hild(descriptio n);
    XmlElement channel = rssFeed.SelectS ingleNode("/rss/channel") as
    XmlElement;
    if (channel != null) {
    channel.AppendC hild(newItem);
    rssFeed.Save(@" file.xml");
    }


    --

    Martin Honnen --- MVP XML

    Comment

    • John Hopper

      #3
      RE: inserting a node

      That works great, just what I needed. Thanks!

      Comment

      Working...