Empty node when data specified in xsd
-
I am receiving xml from an external web service that I am consuming in a C# application. The xsd has this line:
Most of the files received have this element set to a value but I have just come across one that has it empty:
Is this valid, or should I raise it with the web service producer?
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
I am receiving xml from an external web service that I am consuming in a C# application. The xsd has this line:
Most of the files received have this element set to a value but I have just come across one that has it empty:
Is this valid, or should I raise it with the web service producer?
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
I would expect that a value of 0 to 255 would be present for an element marked as byte and it should never be empty. It caused the .NET
XmlSerializer
to throw an exception when deserializing the data. I have done a work around by deserializing to a string instead and having an additional property that returns the result parameter ofbyte.TryParse
on the string, but it's a bit messy.Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
I would expect that a value of 0 to 255 would be present for an element marked as byte and it should never be empty. It caused the .NET
XmlSerializer
to throw an exception when deserializing the data. I have done a work around by deserializing to a string instead and having an additional property that returns the result parameter ofbyte.TryParse
on the string, but it's a bit messy.Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
If you think it's wrong then you should talk to the provider of the XML data.
Use the best guess
I have raised it with them, but not being very knowledgeable in the finer points of XML/XSD I wasn't sure about it's validity.
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
I have raised it with them, but not being very knowledgeable in the finer points of XML/XSD I wasn't sure about it's validity.
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Try making the byte a nullable. As far as I know byte is generally a value type which means it can't be null. e.g. in c#
byte? elementName
-
I have raised it with them, but not being very knowledgeable in the finer points of XML/XSD I wasn't sure about it's validity.
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
I have had a look round a few sites but could not find a definitive statement on this.
Use the best guess
The dev at the company who provide the web service got back to me saying there should always be a value, and they would of course fix it.
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
Try making the byte a nullable. As far as I know byte is generally a value type which means it can't be null. e.g. in c#
byte? elementName
Yes, you are correct about byte being a value type (in .NET anyway). I haven't tried using nullable so don't know how the XmlSerializer will respond to it - could be interesting!
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
I am receiving xml from an external web service that I am consuming in a C# application. The xsd has this line:
Most of the files received have this element set to a value but I have just come across one that has it empty:
Is this valid, or should I raise it with the web service producer?
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)It is valid -- but, the creator of the XSD did not indicate that it was required -- and you have assumed that it is required. If your code cannot tolerate that -- then modify the XSD to make it required and have whoever produces the XML give it a default value.... However, this is simply pushing it off to the side. This is an issue that does not relate to XML per se -- it relates to best practices about defining and validating data. The XSD defines the structure and rules of XML -- so the designer of the schema must describe the data perfectly and consumers must not make assumptions that are not supported by the XSD.