473,395 Members | 1,762 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,395 software developers and data experts.

XmlSerialization to XmlNode

I have a schema that I load into classes that mirror the schema using
the XmlSerialization. The schema contains an xsd:Any that I load into
'Extra' as follows:

[XmlElement(ElementName="Extra")] public XmlNode Extra { get { return
extra;} set { extra = value;}}

However, if I have:

<Something>
<Extra>
<a>something</a>
<b>another thing</b>
</Extra>
</Something>

I would expect Extra to contain an XmlNode of :

<Extra>
<a>something</a>
<b>another thing</b>
</Extra>

But it doesn't : it contains :

<a>something</a>

Is there any attributes etc I can set to get the full element to be
retained ?

TIA

Dominic
Nov 12 '05 #1
1 1367
Yes, when I use

// [XmlElement(ElementName="Extra")]
[XmlAnyElement]
public System.Xml.XmlElement Any;

I get the behavior you seek.
note: the attribute is XmlAnyElement, not XmlElement. Also, omit the name.
If you want to allow more than one element, like so:

<Something>
<Extra>
<a>something</a>
<b>another thing</b>
</Extra>
<foo/>
<bar>
<blah/>
</bar>
</Something>

then specify an array:
[XmlAnyElement]
public System.Xml.XmlElement[] Any;

-Dino
"Dominic Messenger" <dm********@verdantsys.com> wrote in message
news:9d**************************@posting.google.c om...
I have a schema that I load into classes that mirror the schema using
the XmlSerialization. The schema contains an xsd:Any that I load into
'Extra' as follows:

[XmlElement(ElementName="Extra")] public XmlNode Extra { get { return
extra;} set { extra = value;}}

However, if I have:

<Something>
<Extra>
<a>something</a>
<b>another thing</b>
</Extra>
</Something>

I would expect Extra to contain an XmlNode of :

<Extra>
<a>something</a>
<b>another thing</b>
</Extra>

But it doesn't : it contains :

<a>something</a>

Is there any attributes etc I can set to get the full element to be
retained ?

TIA

Dominic

Nov 12 '05 #2

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

Similar topics

2
by: STom | last post by:
I have just started reading up on XMLSerialization and still do not understand the practical use of this technology. For example, if I have to know the class type on the client and on the web...
3
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
5
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
0
by: A programmer desperatly needing help! | last post by:
I use the xmlserialization on asp.net pages and on previous machines it never gave a problem. But now i somethings get a: Timed out waiting for a program to execute. The command being executed was...
4
by: pfrisbie | last post by:
I am developing a Web Services interface with C# and our partner is using Java (Axis 1.1). They require me to include xsi:types in the SOAP Messages I send them. For example: <Partner...
3
by: Joe Cool | last post by:
I have an XML file that is created by an application that I do not have the source to and have no control over at all. I would like to read this XML file using VS2005 VB with XMLSerialization. The...
3
by: LW | last post by:
Hi! I am getting the following error message for my fairly simple web service. I have classes and have two DataSets that reference the same classes. The error is: The XML element named...
1
by: Frank | last post by:
Hi, Let's say I have a file named myFile.xml Within that file I have blocks of data which I'd like to add at different times during the day. e.g. <LogEntry>
0
by: IanWright | last post by:
This is a little bit more of an advanced topic for serialization. For those who don't know what XML serialization is, then this probably isn't for you just yet. For those that do, you may have come...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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
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,...

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.