Dear all,
I have a set of c# data classes wich i need to fill their data from xml files. serialization looks to be the best way to accomplish this task.
Since the data classes are compiled and i don't have control on the xml structure, I tried using the xmlAttributeOve rrides class, to instruct the serializer. Looks like I'm doing something basically wrong, since I fail to do that even with a very simple example.
I would be delitaed if you could take a look at the code, and try to figure out what's wrong there.
Thanks in advance,
Zion.
The data class to be deserialized:
public class MyBead
{
public MyBead() {}
public int BeadID;
}
The input xml:
<CurveGraphPoin t><BeadType BeadID="17"/></CurveGraphPoint >
The deserializing function:
private void btnConvert_Clic k(object sender, System.EventArg s e)
{
Stream fs = new FileStream(txtF ile.Text, FileMode.Open);
XmlReader reader = new XmlTextReader(f s);
Type type = typeof(MyBead);
XmlAttributeOve rrides attOverrides = new XmlAttributeOve rrides();
XmlAttributes attrs = new XmlAttributes() ;
//Define the root element in the XML
XmlRootAttribut e ra = new XmlRootAttribut e("CurveGraphPo int");
attrs.XmlRoot = ra;
XmlElementAttri bute ea = new XmlElementAttri bute("BeadType" , typeof(MyBead)) ;
attrs.XmlElemen ts.Add(ea);
attOverrides.Ad d(type, attrs);
XmlSerializer serializer = new XmlSerializer(t ype, attOverrides);
object obj = serializer.Dese rialize(reader) ;
reader.Close();
} 1 1266
Problem solved.
Thanks for everyone that tried to help.
"Zion Zadik" <zz****@012.net .il> wrote in message news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Dear all,
I have a set of c# data classes wich i need to fill their data from xml files. serialization looks to be the best way to accomplish this task.
Since the data classes are compiled and i don't have control on the xml structure, I tried using the xmlAttributeOve rrides class, to instruct the serializer. Looks like I'm doing something basically wrong, since I fail to do that even with a very simple example.
I would be delitaed if you could take a look at the code, and try to figure out what's wrong there.
Thanks in advance,
Zion.
The data class to be deserialized:
public class MyBead
{
public MyBead() {}
public int BeadID;
}
The input xml:
<CurveGraphPoin t><BeadType BeadID="17"/></CurveGraphPoint >
The deserializing function:
private void btnConvert_Clic k(object sender, System.EventArg s e)
{
Stream fs = new FileStream(txtF ile.Text, FileMode.Open);
XmlReader reader = new XmlTextReader(f s);
Type type = typeof(MyBead);
XmlAttributeOve rrides attOverrides = new XmlAttributeOve rrides();
XmlAttributes attrs = new XmlAttributes() ;
//Define the root element in the XML
XmlRootAttribut e ra = new XmlRootAttribut e("CurveGraphPo int");
attrs.XmlRoot = ra;
XmlElementAttri bute ea = new XmlElementAttri bute("BeadType" , typeof(MyBead)) ;
attrs.XmlElemen ts.Add(ea);
attOverrides.Ad d(type, attrs);
XmlSerializer serializer = new XmlSerializer(t ype, attOverrides);
object obj = serializer.Dese rialize(reader) ;
reader.Close();
} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Zion Zadik |
last post by:
Dear all,
I have a set of c# data classes which i need to fill their data from xml
files. serialization looks to be the best way to accomplish this task.
Since the data classes are compiled and i don't have control on the xml
structure, I tried using the xmlAttributeOverrides class, to instruct the
serializer.
I was able to override the attributes for the root element, but I'm having
problems understanding how to deserialize arrays.
|
by: Stuart Robertson |
last post by:
I am trying to find a solution that will allow me to use XmlSerializer to serialize/deserialize a collection of objects where a given object is shared between two or more other objects, and not create duplicate XML representations of the shared object, but instead use IDREFs to refer to the shared object.
The XML I'm trying to produce is as follows (where "href" is an IDREF):
<?xml version="1.0" encoding="utf-8"?>
<MyRootClass...
|
by: Mark Turner |
last post by:
Help!
I want to serialize mu C# objects uzing the xmlserializer
class. It works well whem all my classes are flat, but
when I use inheritence to split the data and
implementation I get an "unknown element" exception.
namespace A
{
|
by: Daniel Lim |
last post by:
When using XmlSerializer, I notice that it does not normalize the
single quote and double quote characters, i.e. does not change ' to
' and " to ". However, it does normalize other characters,
like changing ampersand to &
Here is my code:
---- start of code --------
MyClass *myClass = MyClass() ;
XmlSerializer *xs = new XmlSerializer( __typeof( MyClass ) ) ;
|
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
| |
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.
|
by: Lloyd Dupont |
last post by:
I get an XmlDocument from an external source.
I want to load it/map it to C# class.
I'm creating classes as I learn about the format. many tag are yet unparsed,
but that seems ok for the XmlSerializer, great!
Now here is my problem.
let say my document conceptually map to classes like that:
public class Foo
|
by: Ian Armitage |
last post by:
Hi,
I am having problems using the XmlSerializer from within a signed assembly.
I have narrowed down the problem to a compilation error (CS0647) occuring
when .NET tries to compile code generated by the XmlSerializer. The JIT
compiler gives an error when trying to process the following attribute: -
.
To make matters worse, this problem is intermittent. I have seen various
|
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= |
last post by:
Hi,
I am using XML serialization for the first time and I have noticed
something unexpected. The object I am serializing contains a field
private NumericSettings _numericSettings;
public NumericSettings NumericSettings
{
get { return _numericSettings; }
}
|
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...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |