Each time I serialize an object using XmlSerializer I get a structure like
this:
<?xml version="1.0"?>
<MyType>
..
..
</MyType>
<?xml version="1.0"?>
<MyType>
..
..
</MyType>
Instead I would like
<?xml version="1.0"?>
<MyRootThatIWil lWriteToTheStre am>
<MyType>
..
..
</MyType>
<MyType>
..
..
</MyType>
</MyRootThatIWill WriteToTheStrea m>
So in other words, can I avoid writing the XML 1.0 decoration header each
time?
--
Thanks 3 2810
An XML document can only have 1 root, so you have to add the objects to a
container, such as a List. It'll serialize out to <ArrayOfAnyType unless
you use a type-specific collection, though. Since all your objects are of
the same type, it'll serialize to ArrayOfMyType
"Thyme" <Th***@discussi ons.microsoft.c omwrote in message
news:7C******** *************** ***********@mic rosoft.com...
Each time I serialize an object using XmlSerializer I get a structure like
this:
<?xml version="1.0"?>
<MyType>
.
.
</MyType>
<?xml version="1.0"?>
<MyType>
.
.
</MyType>
Instead I would like
<?xml version="1.0"?>
<MyRootThatIWil lWriteToTheStre am>
<MyType>
.
.
</MyType>
<MyType>
.
.
</MyType>
</MyRootThatIWill WriteToTheStrea m>
So in other words, can I avoid writing the XML 1.0 decoration header each
time?
--
Thanks
Thanks. I have object of different types. I have tried with Object[] and
ArrayList but when I serialize I get an exception:
Unhandled Exception: System.InvalidO perationExcepti on: There was an error
generating the XML document. ---System.InvalidO perationExcepti on: The type
Company.System. Name.SchemaType was not expected. Use the XmlInclude or
SoapInclude attribute to specify types that are not known statically.
--
Thanks
"Keith Patrick" wrote:
An XML document can only have 1 root, so you have to add the objects to a
container, such as a List. It'll serialize out to <ArrayOfAnyType unless
you use a type-specific collection, though. Since all your objects are of
the same type, it'll serialize to ArrayOfMyType
"Thyme" <Th***@discussi ons.microsoft.c omwrote in message
news:7C******** *************** ***********@mic rosoft.com...
Each time I serialize an object using XmlSerializer I get a structure like
this:
<?xml version="1.0"?>
<MyType>
.
.
</MyType>
<?xml version="1.0"?>
<MyType>
.
.
</MyType>
Instead I would like
<?xml version="1.0"?>
<MyRootThatIWil lWriteToTheStre am>
<MyType>
.
.
</MyType>
<MyType>
.
.
</MyType>
</MyRootThatIWill WriteToTheStrea m>
So in other words, can I avoid writing the XML 1.0 decoration header each
time?
--
Thanks
Have you tried mapping an XML namespace to that particular type via the
XmlSerializer(X mlNameTable) constructor? Also, you could just mark the
class with [XmlInclude(type of(Company.Syst em.Name.SchemaT ype))] to help the
serializer a bit with knowing how to serialize the type.
You may also run into an issue if your classes implement interfaces, as I
recall having issues trying to deserialize Winform objects, and the
interfaces kept biting me. I ditched XmlSerializer altogether for my
configuration API due to that limitation, going with a sorta home-rolled
XAML instead (although XAML wasn't suitable as a serialization format
because it resides in the WPF assemblies rather than a more general purpose
one, whereas I'm using config serialization in a non-UI library.) Worst
comes to worst, you can always go that route as long as your custom
serializer is the only one (de)serializing . This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tom Kent |
last post by:
I have an array list of objects that I want to serialize into an XML file. I have tried this using the following code, but it gives me an error message
An unhandled exception of type 'System.InvalidOperationException' occurred in system.xml.dl
Additional information: There was an error generating the XML document
I'm not sure if this is the way that I should go about serializing an array of objects like this, but I would like to get them...
|
by: Ivo Bronsveld |
last post by:
All,
I have quite a challenging task ahead of me. I need to write an object model
(for code access) based on a schema, which cannot be made into a dataset
because of it's complexity.
So I created a couple of objects and serializing it into XML based upon the
schema works perfectly.
The XML / Schema looks something like this:
|
by: Bruno Jouhier |
last post by:
Is there a way to serialize a graph of objects and get the output as an XML
document, without first serializing to text and then parsing the text (I
know how to do this but I find it really silly and inefficient).
I googled around and from what I found, the answer is NO. Am I missing
something obvious? Is there something new coming in .NET 2.0?
Of course, I'm also interested in the reverse operation (deserializing
directly from...
|
by: Tobias Zimmergren |
last post by:
Hi, just wondering what serializing really is, and howto use it?
Thanks.
Tobias
__________________________________________________________________ Tobias
ICQ#: 55986339 Current ICQ status: + More ways to contact me
__________________________________________________________________
|
by: Dave Veeneman |
last post by:
When does serializing objects make more sense than persisting them to a
database? I'm new to object serialization, and I'm trying to get a feel for
when to use it.
Here is an example: I'm writing an accounting application. I have a chart of
accounts in the form of a containment hierarchy. A GeneralLedger contains a
number of Accounts, and each of these Accounts can contain a Aubledger,
which contains its own Accounts, and so on. The...
| |
by: JackRazz |
last post by:
I'm trying to serialize a collection to a file stream by serializing each object
individually. The code below works fine with the BinaryFormatter, but the
SoapFormatter reads the first object and just goes to the end of the file. After
reading the first object, the fStream.Position is pointed to the end of the file.
The collection serializes/deserilizes fine when I just serialize the hashtable vs.
each object in the hashtable.
Does...
|
by: axr |
last post by:
Having trouble with Serilization of objects that contain members which are of
type Interface
eg
public class SomeClass
{
ISomeInterface1 itf1;
ClassType1 ct1;
ISomeInterface2 itf2;
|
by: Max |
last post by:
Due to the behaviour of a particular COM object, I need to ensure that a
request for a particular ASP page is finalized before another request for
the page is processed. Does IIS have a way to ensure that subsequent
requests will be queued until the current request is completed?
If not, can IIS be configured to use seperate processes to satisfy requests
for a nominated ASP page?
Thanks in advance.
|
by: falcon198198 |
last post by:
Greetings:
I was hoping for some advice on an application. Here is what I am
working on:
Basically I have a bigger application that is having a printing
problem making multiple copies of a pdf so I set off to write a
program that can watch a folder using filesystemwatcher. From the
events that this generates I created a class and instantiated an
object that will hold information like full path and last write time.
I want to be able to...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
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,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |