Solved

Invalid Characters in XML

Posted on 2009-07-03
2
430 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Video Player 12 27
Install Problem 13 34
Release Dynamically Allocated Memory in C# 3 38
What are the simplest ways to create a Merge Sort? 3 29
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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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