Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 10th, 2006, 08:35 PM
John Hopper
Guest
 
Posts: n/a
Default 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./resultsbycasenumber.asp?type=3&year=2005&number=17 284&myPage=searchbycasenumber.asp</link>
<description>Edwin 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="false">f824721b-ba52-429e-a6ad-5b7a5979db51</guid>
<description>DECISION: 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>

  #2  
Old August 11th, 2006, 03:35 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: inserting a node



John Hopper wrote:
Quote:
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.CreateElement("item");
XmlElement description = rssFeed.CreateElement("description");
description.InnerText = "description goes here";
newItem.AppendChild(description);
XmlElement channel = rssFeed.SelectSingleNode("/rss/channel") as
XmlElement;
if (channel != null) {
channel.AppendChild(newItem);
rssFeed.Save(@"file.xml");
}


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
  #3  
Old August 11th, 2006, 04:15 PM
John Hopper
Guest
 
Posts: n/a
Default RE: inserting a node

That works great, just what I needed. Thanks!
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles