Solved

Invalid Characters in XML

Posted on 2009-07-03
2
426 Views
Last Modified: 2012-05-07
Hi,

I am importing an XML file in c#.net using  .ReadXml(xmlFileName, XmlReadMode.InferSchema)

Part of the XML file has Cdata[] wrapped around the data, however, the exception invalid character is being thrown.  I thought the point of CData was to tell the importer that it is not mark up language.

Is there anything I can do to get this to pass?

thanks
0
Comment
Question by:kinton
2 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
well, indeed CDATA is not totally ignored by the parser. For example, cannot put a > sign inside CDATA, you have to use > to escape it. If not, CDATA will assume that is portion has finished. The same for other XML character entities:
http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
0
 
LVL 12

Accepted Solution

by:
ShazbotOK earned 500 total points
Comment Utility
Start with reading the Xml in using a XmlReader setting the validation to none then use the reader to import into the dataset - see if that does the job for you...
            System.Xml.XmlReaderSettings xmSettings = new System.Xml.XmlReaderSettings();

            xmSettings.ValidationType = System.Xml.ValidationType.None;

            System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(((System.IO.Stream)new System.IO.MemoryStream(System.Text.UTF8Encoding.UTF8.GetBytes("MyXmlString"))), xmSettings);

            System.Data.DataSet ds = new System.Data.DataSet();

            ds.ReadXml(reader);

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now