473,396 Members | 2,009 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,396 software developers and data experts.

Deserialize empty XML element (VB.NET)

I'm having some trouble figuring out how to deserialize an empty XML
element in VB.NET. Let's say I'm trying to deserialize XML such as:
<Order>
<OrderRefNumber/>
<Customer>Bob</Customer>
</Order>

I would then have a simple entity object to represent the XML data.
That object would have a property such as:

'---------------- begin code -----------
<System.Xml.Serialization.XmlElementAttribute(Form :=System.Xml.Schema.XmlSchemaForm.Unqualified)>
_
Public Property OrderRefNumber() As Long
Get
Return Me.refNumber
End Get
Set(ByVal Value As Long)
Me.refNumber = Value
End Set
End Property

<XmlIgnore()> _
Public Property OrderRefNumberSpecified() As Boolean
Get
Return Not Me.refNumber = 0
End Get
Set(ByVal Value As Boolean)
If Not Value Then
Me.refNumber = 0
End If
End Set
End Property
'--------------- end code ----------

Where Me.refNumber is a private long field.

Whenever I try to deserialize the XML, I get the following exception
message:
System.InvalidOperationException: There is an error in XML document
(23, 23). ---> System.FormatException: Input string was not in a
correct format.
at System.Number.ParseInt64(String s, NumberStyles style,
NumberFormatInfo info)
at System.Xml.XmlConvert.ToInt64(String s)
........

I'm pretty sure that the XmlSerializer is having trouble deserializing
the empty OrderRefNumber element. How do I fix this?
Thanks!

Nov 12 '05 #1
1 2484
Nevermind.

Nov 12 '05 #2

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

Similar topics

3
by: Massimiliano Alberti | last post by:
How can I insert an empty element in a list? The insert method has as a parameter the source object to insert... So you have to use it in this way: (where MyObject is an object with only a member,...
6
by: Matt | last post by:
How can XSL detect empty elements, for example, <author></author> or <author/> ?? The XML structure can be <book> <author></author> <title></title> </book> The XSL has the following
18
by: Tjerk Wolterink | last post by:
i have the following rule, <xsl:template match="br"> <br/> </xsl:template> This should convert all <br/> to <br/> but, my transformer transforms it all to
2
by: adrian | last post by:
Hi I'm having the following problem: im my xml file there is an element called <gebdatum>22.09.79</gebdatum> (date of birth in english). this might be full (like in the example) or empty. in...
7
by: Albert Greinöcker | last post by:
Hi NG, how can I force Xalan (Java) not to create an empty element when there is nothing between begin and end tag, which means that e.g. <myTag></myTag> ....does not become... <myTag/>
7
by: kumar.senthil | last post by:
Hi, I'm using XmlSerializer to create an object from the XML string. I would like to know whether I can get a null value for an empty XML element. Actually the XmlSerializer assigns "" (empty...
1
by: Bill Nguyen | last post by:
below is a very simple XML file. I use ReadXml to read data. When it reaches an empty element as <Product / below, my program crashes. The error: System.NullReferenceException: Object reference...
5
by: Valery | last post by:
In the following XML: <?xml version="1.0" encoding="utf-8" ?> <Plcy service="ILiability" boId ="LifePolicy, 1"> <Prem service="IPremium" boId ="RegularPremium, 1"></Prem> <L1...
2
by: jy43 | last post by:
I am writing a method for a web service that returns an empty element.(not null) The SOAP generate the response XML message using shorthand format for the empty return object. < soap:Body > ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
tracyyun
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...
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.