473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

DeserializeObject with XmlCDataSection

1
Hi I have the following class
Expand|Select|Wrap|Line Numbers
  1. [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
  2. [System.SerializableAttribute()]
  3. [System.Diagnostics.DebuggerStepThroughAttribute()]
  4. [System.ComponentModel.DesignerCategoryAttribute("code")]
  5. [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
  6. public partial class PageFile
  7. {
  8.     private string parentGuidField;
  9.     private string nameField;
  10.  
  11.     public string ParentGuid
  12.     {
  13.         get
  14.         {
  15.             return this.parentGuidField;
  16.         }
  17.         set
  18.         {
  19.             this.parentGuidField = value;
  20.         }
  21.     }
  22.     public XmlCDataSection Name
  23.     {
  24.         get
  25.         {    
  26.             XmlDataDocument doc = new XmlDataDocument();
  27.             XmlCDataSection cd = doc.CreateCDataSection(this.nameField);
  28.             return cd;
  29.         }
  30.         set
  31.         {        
  32.             this.nameField = value.Value;
  33.         }
  34.     }
  35. }
  36.  
I am wanting to deserialize an xml string using the following generic deserializing class:
Expand|Select|Wrap|Line Numbers
  1. public static T DeserializeObject<T>(string XML)
  2. {
  3.        using (StringReader stringreader = new StringReader(XML))
  4.        {
  5.             XmlSerializer serializer = new XmlSerializer(typeof(T));
  6.              return (T)serializer.Deserialize(stringreader);
  7.         }
  8. }
using :

DeserializeObject<PageFile>(myXmlString);

When I do this I get the following error:

"Unable to cast object of type 'System.Xml.XmlText' to type 'System.Xml.XmlCDataSection'."

If "Name" was a string everything works fine. The problem is I have to have "Name" as a XmlCDataSection, how do I Deserialize my PageFile class using the DeserializeObject method that I use else where in my project?

Many thanks
Jun 15 '10 #1
0 1303

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: sd | last post by:
Hello All, I aplogize if this has already been answered however I couldn't find anything related to this... I have bunch of webservices written in vb.net returning native data types, due to...
3
by: Yasutaka Ito | last post by:
Hi folks! I have a DataSet, which I'm writing into XML using the DataSet.WriteXML() method. Now, I want to write the cell's data/text as CDATA, when it is written into an XML. For example, I...
2
by: Leszek | last post by:
Hello, I have the following code: // Read the XML document from the hard-drive. XmlDocument doc = new XmlDocument(); doc.Load("doc.xml"); // Create the document's root. XmlElement root =...
0
by: DotNetJunkies User | last post by:
I have to deserialize an XML document to objects and then serialize it back to XML to pass to the stored proc. I am attaching partial code. After this , I also have to serialize Here is the XML :...
1
by: Angela | last post by:
I am getting an error when I attempt to access a node with SelectSingleNode(): "The expression passed to this method should result in a NodeSet." I understand there is some confusion when you have...
2
by: Munish | last post by:
(VS.NET 2K3, C#) Hi, I need to serialize/deserialize an element using XmlSerializer that can contain any valid XML including a CDATA section. public class Test { public XmlElement...
4
by: m96 | last post by:
hi, i have a problem with XmlDeserilisation which drives me crazy. i know i must be missing something very trivial... i'm trying to parse the folling xml file i really would appreciate any...
0
by: Raed Sawalha | last post by:
Dear: I'm working web application that expect to pass an class object to DLL(Class Lib) I just Attached the DLL File into Web Solution ( DLL is located in other machine), inside the class...
0
by: boris.golubov | last post by:
I'm trying to write an object hierarchy that is serialized into/from XML file of the following structure: <?xml version='1.0'> <Session> <Level1 attr1="1"> <Level2 attr2="11">TEXT11</Level2>...
2
by: Frank | last post by:
Hi All, I've been yanking my hair out all day over this one, and finally decided to grab some sample code from MSDN, only to find the exact same problem What's the problem? The problem is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.