473,837 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
+ 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.

[XmlRootAttribut e]
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 9743
The object model to deserialize unwrapped [CDATA] nodes should be different:
you need to use XmlNode (or XmlNode[]) instead of XmlElement

[XmlRootAttribut e]

public class Test

{

[XmlAnyElement]

public XmlNode Anything;

}

"Munish" <Mu****@discuss ions.microsoft. com> wrote in message
news:B6******** *************** ***********@mic rosoft.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.

[XmlRootAttribut e]
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
8352
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, the easiest way to represent it would be to put the embedded XML example inside a CDATA section. But if the example has a CDATA section itself, then the ending delimiter will be interpreted as the end of the "real" CDATA section. Here's even a...
3
8068
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
8509
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. I, too, am getting nasty FileNotFound exceptions. I've read, and digested the article, and I think I've found a bug -- it's difficult to track, though it does happen often.
4
1995
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 working fine but when I try to instantiate an XmlSerializer object with: Dim xmls As New XmlSerializer(GetType(CLayerDefinition)) I get the following error:
11
6477
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); XPathNavigator nav = docNav.CreateNavigator(); XmlDocument doc = new XmlDocument(); doc.LoadXml("<DocumentData></DocumentData>"); XmlElement elem = doc.CreateElement(currentNodeName);
12
4020
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 //<!]> Is this trick grounded in any real information about HTML vs XHTML? I
7
3986
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
4109
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. System.Xml.Serialization.XmlRootAttribute(Namespace = "http:// www.TestNameSpace.org/Test-4-4", IsNullable = false)] class Root { public virtual Abstract_message Message
6
4825
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 city values should display in city selection field and when user select any one city value then this state of this city should be display auto in state selection field without user selection. please solve my prolem. Thank you.
0
9852
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10583
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10642
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9420
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7014
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5680
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4481
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 we have to send another system
2
4062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3128
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.