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 7845693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:19:29+00:00 2026-06-02T17:19:29+00:00

I saw this question already, but I didnt see an answer.. So I get

  • 0

I saw this question already, but I didnt see an answer..

So I get this error:

The ':' character, hexadecimal value 0x3A, cannot be included in a name.

On this code:

    XDocument XMLFeed = XDocument.Load("http://feeds.foxnews.com/foxnews/most-popular?format=xml");
    XNamespace content = "http://purl.org/rss/1.0/modules/content/";

    var feeds = from feed in XMLFeed.Descendants("item")
        select new
        {
            Title = feed.Element("title").Value,
            Link = feed.Element("link").Value,
            pubDate = feed.Element("pubDate").Value,
            Description = feed.Element("description").Value,
            MediaContent = feed.Element(content + "encoded")
        };

    foreach (var f in feeds.Reverse())
    {
        ....
    }

An item looks like that:

<rss>    
<channel>

....items....

<item>
<title>Pentagon confirms plan to create new spy agency</title>
<link>http://feeds.foxnews.com/~r/foxnews/most-popular/~3/lVUZwCdjVsc/</link>
<category>politics</category>
<dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/" />
<pubDate>Tue, 24 Apr 2012 12:44:51 PDT</pubDate>
<guid isPermaLink="false">http://www.foxnews.com/politics/2012/04/24/pentagon-confirms-plan-to-create-new-spy-agency/</guid>
<content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[|http://global.fncstatic.com/static/managed/img/Politics/panetta_hearing_030712.jpg<img src="http://feeds.feedburner.com/~r/foxnews/most-popular/~4/lVUZwCdjVsc" height="1" width="1"/>]]></content:encoded>
<description>The Pentagon confirmed Tuesday that it is carving out a brand new spy agency expected to include several hundred officers focused on intelligence gathering around the world.&amp;amp;#160;</description>
<dc:date xmlns:dc="http://purl.org/dc/elements/1.1/">2012-04-4T19:44:51Z</dc:date>
<feedburner:origLink>http://www.foxnews.com/politics/2012/04/24/pentagon-confirms-plan-to-create-new-spy-agency/</feedburner:origLink>
</item>

....items....

</channel>
</rss>    

All I want is to get the “http://global.fncstatic.com/static/managed/img/Politics/panetta_hearing_030712.jpg&#8221;, and before that check if content:encoded exists..

Thanks.

EDIT:
I’ve found a sample that I can show and edit the code that tries to handle it..

EDIT2:
I’ve done it in the ugly way:

text.Replace("content:encoded", "contentt").Replace("xmlns:content=\"http://purl.org/rss/1.0/modules/content/\"","");

and then get the element in the normal way:

MediaContent = feed.Element("contentt").Value
  • 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-06-02T17:19:33+00:00Added an answer on June 2, 2026 at 5:19 pm

    The following code

        static void Main(string[] args)
        {
    
                var XMLFeed = XDocument.Parse(
    @"<rss>    
    <channel>
    
    ....items....
    
    <item>
    <title>Pentagon confirms plan to create new spy agency</title>
    <link>http://feeds.foxnews.com/~r/foxnews/most-popular/~3/lVUZwCdjVsc/</link>
    <category>politics</category>
    <dc:creator xmlns:dc='http://purl.org/dc/elements/1.1/' />
    <pubDate>Tue, 24 Apr 2012 12:44:51 PDT</pubDate>
    <guid isPermaLink='false'>http://www.foxnews.com/politics/2012/04/24/pentagon-confirms-plan-to-create-new-spy-agency/</guid>
    <content:encoded xmlns:content='http://purl.org/rss/1.0/modules/content/'><![CDATA[|http://global.fncstatic.com/static/managed/img/Politics/panetta_hearing_030712.jpg<img src='http://feeds.feedburner.com/~r/foxnews/most-popular/~4/lVUZwCdjVsc' height='1' width='1'/>]]></content:encoded>
    <description>The Pentagon confirmed Tuesday that it is carving out a brand new spy agency expected to include several hundred officers focused on intelligence gathering around the world.&amp;amp;#160;</description>
    <dc:date xmlns:dc='http://purl.org/dc/elements/1.1/'>2012-04-4T19:44:51Z</dc:date>
    <!-- <feedburner:origLink>http://www.foxnews.com/politics/2012/04/24/pentagon-confirms-plan-to-create-new-spy-agency/</feedburner:origLink> -->
    </item>
    
    ....items....
    
    </channel>
    </rss>");
                XNamespace contentNs = "http://purl.org/rss/1.0/modules/content/";
                var feeds = from feed in XMLFeed.Descendants("item")
                            select new
                                       {
                                           Title = (string)feed.Element("title"),
                                           Link = (string)feed.Element("link"),
                                           pubDate = (string)feed.Element("pubDate"),
                                           Description = (string)feed.Element("description"),
                                           MediaContent = GetMediaContent((string)feed.Element(contentNs + "encoded"))
                                       };
                foreach(var item in feeds)
                {
                    Console.WriteLine(item);
                }
            }
    
            private static string GetMediaContent(string content)
            {
                int imgStartPos = content.IndexOf("<img");
                if(imgStartPos > 0)
                {
                    int startPos = content[0] == '|' ? 1 : 0;
    
                    return content.Substring(startPos, imgStartPos - startPos);
                }
    
                return string.Empty;
            }
    

    results in:

    { Title = Pentagon confirms plan to create new spy agency, Link = http://feeds.f
    oxnews.com/~r/foxnews/most-popular/~3/lVUZwCdjVsc/, pubDate = Tue, 24 Apr 2012 1
    2:44:51 PDT, Description = The Pentagon confirmed Tuesday that it is carving out
     a brand new spy agency expected to include several hundred officers focused on
    intelligence gathering around the world.&#160;, MediaContent = http://global
    .fncstatic.com/static/managed/img/Politics/panetta_hearing_030712.jpg }
    Press any key to continue . . .
    

    A few points:

    • You never want to treat Xml as text – in your case you removed the namespace declaration but actually if the namespace was declared inline (i.e. without binding to the prefix) or a different prefix would be defined your code would not work even though semantically both documents would be equivalent
    • Unless you know what’s inside CDATA and how to treat it you always want to treat is as text. If you know it’s something else you can treat it differently after parsing – see my elaborate on CDATA below for more details
    • To avoid NullReferenceExceptions if the element is missing I used explicit conversion operator (string) instead of invoking .Value
    • the Xml you posted was not a valid xml – there was missing namespace Uri for feedburner prefix

    This is no longer related to the problem but may be helpful for some folks so I am leaving it

    As far as the contents of the encode element is considered it is inside CDATA section. What’s inside CDATA section is not an Xml but plain text. CDATA is usually used to not have to encode ‘<‘, ‘>’, ‘&’ characters (without CDATA they would have to be encoded as < > and & to not break the Xml document itself) but the Xml processor treat characters in the CDATA as if they were encoded (or to be more correct in encodes them). The CDATA is convenient if you want to embed html because textually the embedded content looks like the original yet it won’t break your xml if the html is not a well-formed Xml. Since the CDATA content is not an Xml but text it is not possible to treat it as Xml. You will probably need to treat is as text and use for instance regular expressions. If you know it is a valid Xml you can load the contents to an XElement again and process it. In your case you have got mixed content so it is not easy to do unless you use a little dirty hack. Everything would be easy if you have just one top level element instead of mixed content. The hack is to add the element to avoid all the hassle. Inside the foreach look you can do something like this:

    var mediaContentXml = XElement.Parse("<content>" + (string)item.MediaContent + "</content>");
    Console.WriteLine((string)mediaContentXml.Element("img").Attribute("src"));    
    

    Again it’s not pretty and it is a hack but it will work if the content of the encoded element is valid Xml. The more correct way of doing this is to us XmlReader with ConformanceLevel set to Fragment and recognize all kinds of nodes appropriately to create a corresponding Linq to Xml node.

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

Sidebar

Related Questions

I saw this post on SO already but it still begs the question, at
I already saw an answer here , but it didn't really answer my question.
I know I asked this question already many times, but I did not get
I saw this question already on this forum but I do not know why
I saw this question asked about C# I would like an answer for PHP.
I already saw this question however, it didn't work for me whatever I tried.
Before you mark this as answered in another post (I already saw those). But
I saw this question : XPathDocument vs. XmlDocument But it doesnt have the info
I'm trying to svn checkout into my public_html folder, but I get this error:
I saw a post on this already, but it didn't really provide a solution

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.