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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:21:08+00:00 2026-05-15T21:21:08+00:00

The code: using (XmlReader xmlr = XmlReader.Create(new StringReader(allXml))) { var items = from item

  • 0

The code:

using (XmlReader xmlr = XmlReader.Create(new StringReader(allXml)))
{
    var items = from item in SyndicationFeed.Load(xmlr).Items
        select item;
}

The exception:

Exception: System.Xml.XmlException: Unexpected node type Element. 
   ReadElementString method can only be called on elements with simple or empty content. Line 11, position 25.
   at System.Xml.XmlReader.ReadElementString()
   at System.ServiceModel.Syndication.Rss20FeedFormatter.ReadXml(XmlReader reader, SyndicationFeed result)
   at System.ServiceModel.Syndication.Rss20FeedFormatter.ReadFeed(XmlReader reader)
   at System.ServiceModel.Syndication.Rss20FeedFormatter.ReadFrom(XmlReader reader)
   at System.ServiceModel.Syndication.SyndicationFeed.Load[TSyndicationFeed](XmlReader reader)
   at System.ServiceModel.Syndication.SyndicationFeed.Load(XmlReader reader)
   at Ionic.ToolsAndTests.ReadRss.Run() in c:\dev\dotnet\ReadRss.cs:line 90

The XML content:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="https://www.ibm.com/developerworks/mydeveloperworks/blogs/roller-ui/styles/rss.xsl" media="screen"?><rss version="2.0" 
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:atom="http://www.w3.org/2005/Atom" >
<channel>
  <title>Software architecture, software engineering, and Renaissance Jazz</title>
  <link>https://www.ibm.com/developerworks/mydeveloperworks/blogs/gradybooch</link>
  <atom:link rel="self" type="application/rss+xml" href="https://www.ibm.com/developerworks/mydeveloperworks/blogs/gradybooch/feed/entries/rss?lang=en" />
  <description>Software architecture, software engineering, and Renaissance Jazz</description>
  <language>en-us</language>
  <copyright>Copyright <script type='text/javascript'> document.write(blogsDate.date.localize (1273534889181));</script></copyright>
  <lastBuildDate>Mon, 10 May 2010 19:41:29 -0400</lastBuildDate>

As you can see, on line 11, at position 25, there’s a script block inside the <copyright> element.

Other people have reported similar errors with other XML documents.

The way I worked around this was to do a StreamReader.ReadToEnd, then do Regex.Replace on the result of that to yank out the script block, before
passing the modified string to XmlReader.Create(). Feels like a hack.


  1. Has anyone got a better approach? I don’t like this because I have to read in a 125k string into memory.

  2. Is it valid rss to include “complex content” like that – a script block inside an element?

  • 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-15T21:21:09+00:00Added an answer on May 15, 2026 at 9:21 pm

    You can subclass XmlTextReader and override ReadElementString to skip or modify the offending element as it’s being read. Still feels like a hack but at least avoids the pre-processing with regex.

    Here’s a simple implementation that gets the job done:

    
    class BrokenFeedXmlReader : XmlTextReader 
    {
        // Additional XmlTextReader constructors can be added in 
        // similar fashion as needed
        public BrokenFeedXmlReader(TextReader input)
            : base(input)
        {
        }
    
        public override string ReadElementString()
        {
            if ("copyright" == Name)
            {
                base.Skip();
                return String.Empty; 
            }
    
            return base.ReadElementString();
        }            
    }
    

    Your example code would then look something like this:

    
    using (XmlReader xmlr = new BrokenFeedXmlReader(new StringReader(allXml)))
    {
        var items = from item in SyndicationFeed.Load(xmlr).Items
                    select item;
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 470k
  • Answers 470k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try using the configSource http://theburningmonk.com/2010/03/dot-net-tips-using-configsource-or-file-attribute-to-externalize-config-sections/ http://msdn.microsoft.com/en-us/library/system.configuration.sectioninformation.configsource.aspx May 16, 2026 at 2:56 am
  • Editorial Team
    Editorial Team added an answer Simplest solution is probably to have a second set of… May 16, 2026 at 2:56 am
  • Editorial Team
    Editorial Team added an answer You need the select function: http://linux.die.net/man/2/select More user-friendly: http://beej.us/guide/bgnet/html/single/bgnet.html#select May 16, 2026 at 2:56 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.