473,748 Members | 2,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlConvert and Object type

I'm looking for a way to retrieve data via
System.Reflecti on.FieldInfo.Ge tValue (which returns an Object) and convert
it to XML using XmlConvert.ToSt ring.

XmlConvert accepts only specified data types, so I could have a big ugly
branching Select statement to call the correct ToString overload... but
there must be an easier way.

Any suggestions?

Cheers,

Jon
Nov 11 '05 #1
2 2066
XmlConvert cannot convert any arbitrary object to XML. For that you need
the XmlSerializer:

YourObjectType t = ...
XmlSerializer s = new XmlSerializer(t ypeof(YourObjec tType));
s.Serialize(Con sole.Out, t);

This will give you all the public members. If you want to also serialize
the private state then use the System.Runtime. Serialization with the
System.Runtime. Serialization.F ormatters.Soap. SoapFormatter class.
"Jon the Blind" <no****@spamfre e.biz> wrote in message
news:e2******** ******@TK2MSFTN GP10.phx.gbl...
I'm looking for a way to retrieve data via
System.Reflecti on.FieldInfo.Ge tValue (which returns an Object) and convert
it to XML using XmlConvert.ToSt ring.

XmlConvert accepts only specified data types, so I could have a big ugly
branching Select statement to call the correct ToString overload... but
there must be an easier way.

Any suggestions?

Cheers,

Jon

Nov 11 '05 #2
Sorry, perhaps I wasn't clear enough about what I need. I'm not looking to
convert complex types, just value types (plus Guids and Strings) passed in a
variable of type Object.

I'm using Reflection to retrieve the values, and I want to insert them into
XML attributes. The safest way to do this is with XmlConvert, but it won't
accept an Object type. I can write a big branching statement for all the
possible actual types of my object (per sample code below), but I was hoping
for something a little more elegant.

Dim xmlString as String
Dim value as Object = CType(myStuffFr omReflection,
FieldInfo).GetV alue(someObj)

If TypeOf(obj) Is String Then
dim s as String = CType(value, String)
xmlString = XmlConvert.ToSt ring(s) ' ToString only has overloads
for strongly-typed variables
ElseIf TypeOf(obj) Is Integer Then
dim i as Integer = CType(value, Integer)
xmlString = XmlConvert.ToSt ring(i)
' etc...
Any suggestions?

Thanks.

Jon


"Jon the Blind" <no****@spamfre e.biz> wrote in message
news:e2******** ******@TK2MSFTN GP10.phx.gbl...
I'm looking for a way to retrieve data via
System.Reflecti on.FieldInfo.Ge tValue (which returns an Object) and convert
it to XML using XmlConvert.ToSt ring.

XmlConvert accepts only specified data types, so I could have a big ugly
branching Select statement to call the correct ToString overload... but
there must be an easier way.

Any suggestions?

Cheers,

Jon

Nov 11 '05 #3

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

Similar topics

0
1874
by: Jim M | last post by:
I use EncodeName in my server side ASPX VB code as shown below. xml_qdata = xml_qdata & "<NoteItem>" & System.Xml.XmlConvert.EncodeName(myReader.Item("Note")) & "</NoteItem>" I THEN LOAD xml_qdata into an XML control so that I can read the XML with javascript on the client. THE PROBLEM is that unescape does not convert the x200 style characters. HOW CAN I ESCAPE DATA FOR XML IN SERVER SIDE ASPX VB CODE AND THEN UNESCAPE
16
25419
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have the properties: mode1, mode2, and mode3. This seems simple but I can't quite figure it out... Any ideas anyone?
2
3765
by: Shawn Anderson | last post by:
I have a question and I think I know the answer, but I am looking for confirmation (and maybe a link to some documentation) I have an input string of: "2004-08-01T00:00:00-00:00" When I pass this to XmlConvert.ToDateTime I get a result of "7/31/2004 8:00:00 PM" Can anyone clarify why the result is one day in the past? By thought is
1
2877
by: Chris | last post by:
HI, what is the purpose of XmlConvert.ToString() ? why not just use Convert.ToString() ? e.g. Int32 vInt32 = -2147483648; string s1 = XmlConvert.ToString(vInt32); string s2 = Convert.ToString(vInt32);
100
5274
by: E. Robert Tisdale | last post by:
What is an object? Where did this term come from? Does it have any relation to the objects in "object oriented programming"?
16
2898
by: anonymous.user0 | last post by:
The way I understand it, if I have an object Listener that has registered as a listener for some event Event that's produced by an object Emitter, as long as Emitter is still allocated Listener will stay alive. Is this correct? If this is correct, I've got a problem. Let's say I've got an object Customer that has an PurchaseList (Collection) of Purchase objects. Now, these Purchase objects were pulled from a datasource Datasource. The...
2
1874
by: Soren S. Jorgensen | last post by:
Hi, The docs says (both local and on msdn) that XmlConvert contains methods ToBinHexString and FromBinHexString! But my compiler complains about not finding these methods! Are they not implemented or is something wrong on my box ?? Kr. Soren
2
2654
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
5
3172
by: JH | last post by:
Hi I found that a type/class are both a subclass and a instance of base type "object". It conflicts to my understanding that: 1.) a type/class object is created from class statement 2.) a instance is created by "calling" a class object.
0
8984
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
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,...
0
9530
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, 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...
0
9363
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 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...
0
8237
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
isladogs
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...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.