473,545 Members | 1,351 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 9693
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
8335
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...
3
8019
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
8461
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,...
4
1975
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...
11
6429
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 =...
12
3963
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
3968
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
4076
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
4783
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 ...
0
7467
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...
0
7401
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7756
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5971
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...
0
4944
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...
0
3442
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1879
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
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
703
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...

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.