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 1257
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |