Solved

Invalid Characters in XML

Posted on 2009-07-03
2
431 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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