Ellen Hu

Ellen Hu

  • NA
  • 63
  • 0

hexadecimal value XXXX, is an invalid character When reading XML file

Mar 7 2011 6:24 PM
Hi All,

I have a link of http://www.idealist.org/feeds/volop_en.xml.bz2, from this link to download a zip file, and read its XML to store into SQL server 2008.

Had tried both:

 XmlTextReader reader = new XmlTextReader("C:\\volop_en.xml");

            while (reader.Read())
            {
                   //
            }

AND

         byte[] originalData = null;
            string strUrl = "C:\\volop_en.xml";

            WebClient wc = new WebClient();


            try
            {
                originalData = wc.DownloadData(strUrl);
            }
            catch (WebException)
            {
                // do nothing
            }
            if (originalData != null)
            {
                MemoryStream stream = new MemoryStream(originalData);

                XmlDocument doc = new XmlDocument();

                doc.Load(stream);
              }

Both gets error says " hexadecimal value XXXX, is an invalid character. Line XXXXX, position XXX." If I manually remove that illegal character using replacing all at "volop_en.xml", will have another illegal character comes out.

Since this is a large file, and this source XML file will be updated daily. It seems hard to use replace function, is there a way to ignore those characters? or other suggestion?

Thank you for your time,

ellen


Answers (1)