Main Site Documentation

XML RSS - A first chance exception of type 'System.Xml.XmlException'


#1

Hello - I’m trying to create a simple RSS feed to be read using XmlReader on my Cobra. The XmlReader seems to work OK on most RSS sites that I’ve come across. However, with my simple RSS feed example (copied below), when attempeting the very first xml.Read(), I recieve: “A first chance exception of type ‘System.Xml.XmlException’”. I’m not sure what is wrong with my simple feed example that causes this XmlReader error as it passes the WC3 RSS Validator.

I greatly appriciate any assistance.
Thanks, Carl

<?xml version="1.0" encoding="utf-8"?> Channel Title http://www.any-domain.com Channel Description en-us Item Title 1 Item Description 1 Item Title 2 Item Description 2

#2

Maybe you have found a bug? Can you try to strip pieces out of your XML file till you reach a point where you know what is causing the error?

This will also show you if the code is on your side as well.


#3

I did a quick check on my FEZ Cobra and it works without any execption.

I used a modified version from here for reading the xml file from a USB stick

http://www.microframeworkprojects.com/index.php?title=XML

You can try it by yourself. Make a new FEZ Cobra Console project and add the following code:


using System;
using System.IO;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using GHIElectronics.NETMF.IO;
using GHIElectronics.NETMF.USBHost;
using System.Xml;


namespace XmlFile
{
    public class Program
    {
        static PersistentStorage ps;

        public static void Main()
        {

            Debug.Print("Application started");
            RemovableMedia.Insert += new InsertEventHandler(RemovableMedia_Insert);
            RemovableMedia.Eject += new EjectEventHandler(RemovableMedia_Eject);

            USBHostController.DeviceConnectedEvent += new USBH_DeviceConnectionEventHandler(USBHostController_DeviceConnectedEvent);
            Thread.Sleep(Timeout.Infinite);
            
        }

        static void USBHostController_DeviceConnectedEvent(USBH_Device device)
        {
            if (device.TYPE == USBH_DeviceType.MassStorage)
            {
                Debug.Print("USB Mass Storage detected...");
                ps = new PersistentStorage(device);
                ps.MountFileSystem();
            }
        }

        static void RemovableMedia_Eject(object sender, MediaEventArgs e)
        {
            Debug.Print("Storage \"" + e.Volume.RootDirectory + "\" is ejected.");
        }

        static void RemovableMedia_Insert(object sender, MediaEventArgs e)
        {
            System.IO.FileStream xmfile = File.Open(@ "\USB\Test.xml", FileMode.Open);

            XmlReader xmlr = XmlReader.Create(xmfile);
            try
            {
                while (!xmlr.EOF)
                {
                    xmlr.Read();
                    
                    switch (xmlr.NodeType)
                    {
                        case XmlNodeType.Element:
                            Debug.Print("element: " + xmlr.Name);
                            break;
                        case XmlNodeType.Text:
                            Debug.Print("text: " + xmlr.Value);
                            break;
                        case XmlNodeType.XmlDeclaration:
                            Debug.Print("decl: " + xmlr.Name + ", " + xmlr.Value);
                            break;
                        case XmlNodeType.Comment:
                            Debug.Print("comment " + xmlr.Value);
                            break;
                        case XmlNodeType.EndElement:
                            Debug.Print("end element");
                            break;
                        case XmlNodeType.Whitespace:
                            Debug.Print("white space");
                            break;
                        case XmlNodeType.None:
                            Debug.Print("none");
                            break;
                        default:
                            Debug.Print(xmlr.NodeType.ToString());
                            break;
                    }
                }
            }
            catch (Exception exe)
            {
                string s = exe.Message;
               
            }

        }

    }
}

Did this code throws also an execption?

This is the debug output from VS


#4

Cypher - Thanks, yes my simple RSS feed example works with your code on my Cobra. Your code, at first glance, does not seem significantly different from mine, but I will compare the code more closely late tonight or tomorrow as I have commitments for the rest of today. I wonder if there could be some sort of conflict with other code in my project? Thanks again for your help!
Carl


#5

OK, after a little research, I found my RSS problem. I had written a string method that was supposed to do some useful manipulations to the RSS response string. However, this method was on occasion corrupting the RSS data. Since this was in intermittent problem, it was difficult for me to figure out.

Cypher and Gus, thank you very much for your help.
Carl