Solved

Invalid Characters in XML

Posted on 2009-07-03
2
427 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
ID: 24772300
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
ID: 24788215
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

895 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

13 Experts available now in Live!

Get 1:1 Help Now