Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6821347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:32:05+00:00 2026-05-26T21:32:05+00:00

I’ve a problem to parse my XML File (RSS Feed) in C#. I just

  • 0

I’ve a problem to parse my XML File (RSS Feed) in C#.
I just want to read out the “entry” entries (the root parent – “feed” – is not relevant).
All “entry” entries are almost even, except the part “state”. Some entries doesn’t have that entry.

So i just want to read out the following:
“entry” nodes:

  1. updated
  2. expires
  3. title
  4. summary
  5. state (if exists)

Any suggestions?
Thank you very much.

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
   <updated>2011-01-01T00:00:00+0100</updated>
   <link href="http://www.domain.com" rel="self"/>
   <author>
      <name>Mr X</name>
      <email>Mr_X@domain.com</email>
   </author>
   <title>Some infos....</title>
   <id>domain.com</id>
<entry>
   <updated>2011-01-01T00:00:00Z</updated>
   <expires>2011-01-02T00:00:00Z</expires>
   <title>My first Title</title>
   <id>First ID</id>
  <link type="text/html" rel="alternate"
        href="http://domain.com/firstElement"></link>
   <summary>My first important summary</summary>
   <rights>domain.com</rights>
   <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
         <div>
            <img alt="second" width="32"
                 src="http://domain.com/firstElement.png"/>
         </div>
      </div>
   </content>
</entry>
<entry>
  <updated>2011-01-01T00:00:00Z</updated>
  <expires>2011-01-02T00:00:00Z</expires>
  <title>My second Title</title>
  <state>active</state>
  <id>Second ID</id>
  <link type="text/html" rel="alternate"
        href="http://domain.com/secondElement"></link>
  <summary>My second important summary</summary>
  <rights>domain.com</rights>
  <content type="xhtml">
    <div xmlns="http://www.w3.org/1999/xhtml">
      <div>
        <img alt="second" width="32"
              src="http://domain.com/secondElement.png"/>
      </div>
    </div>
  </content>
  </entry>
</feed>{<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
   <updated>2011-01-01T00:00:00+0100</updated>
   <link href="http://www.domain.com" rel="self"/>
   <author>
      <name>Mr X</name>
      <email>Mr_X@domain.com</email>
   </author>
   <title>Some infos....</title>
   <id>domain.com</id>
<entry>
   <updated>2011-01-01T00:00:00Z</updated>
   <expires>2011-01-02T00:00:00Z</expires>
   <title>My first Title</title>
   <id>First ID</id>
  <link type="text/html" rel="alternate"
        href="http://domain.com/firstElement"></link>
   <summary>My first important summary</summary>
   <rights>domain.com</rights>
   <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
         <div>
            <img alt="second" width="32"
                 src="http://domain.com/firstElement.png"/>
         </div>
      </div>
   </content>
</entry>
<entry>
  <updated>2011-01-01T00:00:00Z</updated>
  <expires>2011-01-02T00:00:00Z</expires>
  <title>My second Title</title>
  <state>active</state>
  <id>Second ID</id>
  <link type="text/html" rel="alternate"
        href="http://domain.com/secondElement"></link>
  <summary>My second important summary</summary>
  <rights>domain.com</rights>
  <content type="xhtml">
    <div xmlns="http://www.w3.org/1999/xhtml">
      <div>
        <img alt="second" width="32"
              src="http://domain.com/secondElement.png"/>
      </div>
    </div>
  </content>
  </entry>
</feed>

My current C# code:

public void ParseXML(XmlDocument xmlFile)
    {
        ArrayList updated = new ArrayList();
        ArrayList expires = new ArrayList();
        ArrayList title = new ArrayList();
        ArrayList summary = new ArrayList();
        ArrayList state = new ArrayList();

        ObservableCollection<TrafficInformation> trafInfo = new ObservableCollection<TrafficInformation>();
        myCollection = trafInfo;
        XmlNodeReader reader = new XmlNodeReader(xmlFile);

        StringBuilder output = new StringBuilder();

        while (reader.Read())
        {
            switch (reader.NodeType)
            {
                case XmlNodeType.Element:
                    if(reader.Name == "updated")
                    {
                        updated.Add(reader.ReadString());
                    }

                    if (reader.Name == "expires")
                    {
                        expires.Add(reader.ReadString());
                    }

                    if (reader.Name == "title")
                    {
                        title.Add(reader.ReadString());
                    }

                    if (reader.Name == "summary")
                    {
                        summary.Add(reader.ReadString());
                    }

                    if (reader.Name == "state")
                    {
                        state.Add(reader.ReadString());
                    }

                    break;
            }
        }
    }

In that case, I don’t have a relationship between the data (if state doesn’t exists).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:32:05+00:00Added an answer on May 26, 2026 at 9:32 pm

    You could use XPath expression for that. Below is complete example on console-appliactaion – as you use xlmns namespace, it requries a little modification of ParseXML method.

    using System;
    using System.Xml;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load("XMLFile1.xml");
                XmlNamespaceManager xmlnm = new XmlNamespaceManager(xmlDocument.NameTable);
                xmlnm.AddNamespace("ns", "http://www.w3.org/2005/Atom");
    
                ParseXML(xmlDocument, xmlnm);
    
                Console.WriteLine("\n---XML parsed---");
                Console.ReadKey();
            }
    
            public static void ParseXML(XmlDocument xmlFile, XmlNamespaceManager xmlnm)
            {
                XmlNodeList nodes = xmlFile.SelectNodes("//ns:updated | //ns:expires | //ns:title | //ns:summary | //ns:state", xmlnm);
    
                foreach (XmlNode node in nodes)
                {
                    Console.WriteLine(node.Name + " = " + node.InnerXml);
                }
            }
        }
    }
    

    // in XPath expression means, you want to select all nodes with specific name, no matter where they are.

    If you want to search only <entry></entry> elements, you can use following:
    "//ns:entry/ns:updated | //ns:entry/ns:expires | //ns:entry/ns:title | //ns:entry/ns:summary | //ns:entry/ns:state"

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm parsing an XML file, the creators of it stuck in a bunch social
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.