473,466 Members | 1,364 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XmlSerializer, XmlAnyElement and CDATA

(VS.NET 2K3, C#)
Hi,
I need to serialize/deserialize an element using XmlSerializer that can
contain any valid XML including a CDATA section.

[XmlRootAttribute]
public class Test
{
[XmlAnyElement]
public XmlElement Anything;
}

This doesn't work with an XML like the following:
<Test><![CDATA[ msgbox "Hi222"]]></Test>

However this works fine:
<Test><Wrap><![CDATA[ msgbox "Hi222"]]></Wrap></Test>

Unfortunately in my case the XML between <Test> comes from outside of my
application and can contain virtually anything. I just need to be able to
read/write this data and may be pass on to someone else. Changing XmlElement
in the example above to XmlLinkedNode doesn't help.

Thanks for your help.
Nov 12 '05 #1
2 9678
The object model to deserialize unwrapped [CDATA] nodes should be different:
you need to use XmlNode (or XmlNode[]) instead of XmlElement

[XmlRootAttribute]

public class Test

{

[XmlAnyElement]

public XmlNode Anything;

}

"Munish" <Mu****@discussions.microsoft.com> wrote in message
news:B6**********************************@microsof t.com...
(VS.NET 2K3, C#)
Hi,
I need to serialize/deserialize an element using XmlSerializer that can
contain any valid XML including a CDATA section.

[XmlRootAttribute]
public class Test
{
[XmlAnyElement]
public XmlElement Anything;
}

This doesn't work with an XML like the following:
<Test><![CDATA[ msgbox "Hi222"]]></Test>

However this works fine:
<Test><Wrap><![CDATA[ msgbox "Hi222"]]></Wrap></Test>

Unfortunately in my case the XML between <Test> comes from outside of my
application and can contain virtually anything. I just need to be able to
read/write this data and may be pass on to someone else. Changing XmlElement in the example above to XmlLinkedNode doesn't help.

Thanks for your help.

Nov 12 '05 #2
Thanks for replying, but that doesn't work. As I mentioned before going to a
common base class of XmlElement and XmlCDataSection (XmlLinkedNode for
example) doesn't help.

Any other way?

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Cade Perkins | last post by:
How can the CDATA ending delimiter "]]>" be represented within a CDATA section itself? Consider an XML document that is intended to contain an embedded, uninterpreted XML example. Generally,...
3
by: Cindy Liu | last post by:
Hi, I use XmlSerializer to serialize xml string. It escapes xml special charaters, like < and > to < and >. How can I stop XmlSerializer to escape these charaters? Thanks in advance!!! Cindy
12
by: SJD | last post by:
I've just read Christoph Schittko's article on XmlSerializer: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp . . . and very informative it is too....
4
by: Steve Long | last post by:
Hello, I hope this is the right group to post this to. I'm trying to serialize a class I've written and I'd like to be able to serialze to both binary and xml formats. Binary serialization is...
11
by: ericms | last post by:
Can anybody show me how to insert a CDATA section using XPathNavigator ? I have tried the follwing with no luck: XmlDocument docNav = new XmlDocument(); docNav.LoadXml(xmlString);...
12
by: Peter Michaux | last post by:
Hi, I am experimenting with some of the Ruby on Rails JavaScript generators and see something I haven't before. Maybe it is worthwhile? In the page below the script is enclosed in //<!]> ...
7
by: Max | last post by:
Hello everyone! Can anyone help me to convert the CDATA expression "CDATA ::= (Char* - (Char* ']]>' Char*)" to Javascript Regular Expression? Thanks, Max
0
by: harshal.borade | last post by:
I am using XmlSerializer with XmlAttributeOverrides. The XmlAttributeOverrides are used for properties which hold element/s derived from "AbstractMessage" type. ...
6
by: dkyadav80 | last post by:
Hi sir, I'm new about xml, javascript. I have two selection field(html) first is city and second is state. the city and state values should be store in xml file. when user select city then all...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.