473,516 Members | 3,064 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get rid of serialized nil attribute

Hello there,

I've got following serializable property:

[XmlElementAttribute("f", IsNullable = true)]
public string[] Field
{
get { return _fields; }
set { _fields = value; }
}

If that array contains null values, the serializer creates following
XML code:

<f>6389</f>
<f d6p1:nil="true" xmlns:d6p1="http://www.w3.org/2001/
XMLSchema-instance" />
<f d6p1:nil="true" xmlns:d6p1="http://www.w3.org/2001/
XMLSchema-instance" />
<f d6p1:nil="true" xmlns:d6p1="http://www.w3.org/2001/
XMLSchema-instance" />
<f>1346.25</f>
<f d6p1:nil="true" xmlns:d6p1="http://www.w3.org/2001/
XMLSchema-instance" />
<f d6p1:nil="true" xmlns:d6p1="http://www.w3.org/2001/
XMLSchema-instance" />

I don't like that "d6p1:nil="true" xmlns:d6p1="http://www.w3.org/2001/
XMLSchema-instance" part. I need an empty f tag, but I don't want to
have the nil and namespace part. How do I get rid of that?

Thanks,
Norbert

Nov 9 '07 #1
2 5305
Norbert Pürringer wrote:
I've got following serializable property:

[XmlElementAttribute("f", IsNullable = true)]
public string[] Field
{
get { return _fields; }
set { _fields = value; }
}

If that array contains null values, the serializer creates following
XML code:

<f>6389</f>
<f d6p1:nil="true" xmlns:d6p1="http://www.w3.org/2001/
XMLSchema-instance" />
<f d6p1:nil="true" xmlns:d6p1="http://www.w3.org/2001/
XMLSchema-instance" />
<f d6p1:nil="true" xmlns:d6p1="http://www.w3.org/2001/
XMLSchema-instance" />
<f>1346.25</f>
<f d6p1:nil="true" xmlns:d6p1="http://www.w3.org/2001/
XMLSchema-instance" />
<f d6p1:nil="true" xmlns:d6p1="http://www.w3.org/2001/
XMLSchema-instance" />

I don't like that "d6p1:nil="true" xmlns:d6p1="http://www.w3.org/2001/
XMLSchema-instance" part. I need an empty f tag, but I don't want to
have the nil and namespace part. How do I get rid of that?
Well you can remove the IsNullable = true from your element, that way
(as long as the type is string/xs:string) the element will have an empty
string value.
As long as you insist on IsNullable = true you will have to live with
the xsi:nil="true" and the namespace declaration as that is the way how
the W3C XSD schema language defines null/nil values to be marked up and
be distinguished from empty string values.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 9 '07 #2
On 9 Nov., 18:14, Martin Honnen <mahotr...@yahoo.dewrote:
Well you can remove the IsNullable = true from your element, that way
(as long as the type is string/xs:string) the element will have an empty
string value.
As long as you insist on IsNullable = true you will have to live with
the xsi:nil="true" and the namespace declaration as that is the way how
the W3C XSD schema language defines null/nil values to be marked up and
be distinguished from empty string values.
Is there really no chance to get at least rid of the namespace? I can
live with xsi:nil="true", but that namespace can extremely multiply
the size of the XML stream.

Norbert

Nov 12 '07 #3

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

Similar topics

1
1110
by: jabailo | last post by:
Suppose I have a windows service, with a FileWatcher class. A file appears, and an event is raised -- but then the server is rebooted or crashes. When the server is rebooted, I want that event state to be where it was. So, can an event be serialized? And can it then be 're-raised' on the program that was responding to it?
2
14955
by: Richard | last post by:
I've used XMLSerializer before to store user settings with great success, but this is the first time I've tried to serialize an Array. It serializes fine, but when I try to deserialize it, I get the following error: There is an error in XML document (0, 0). ---> System.Xml.XmlException: The data at the root level is invalid. Line 1,...
1
1403
by: Julia Beresford | last post by:
Hi I have a c# class defined as follows: public class Registry { /// <remarks/>
1
1894
by: nospam | last post by:
Hi, I have used the xsd tool to generate a class from a schema. I then use the XmlSerializer class to write an object to an XML file. So far so good. However attributes that are set to their default values are not serialized to the XML file. However I would like to force the serializer to write an attribute to the file, even if it is...
7
3662
by: Neal Andrews | last post by:
Hi All, Does anyone know how to stop Events from being serialized in a class that uses the <Serializable()> attribute? I have tried using the <NonSerialized()> attribute but for some bizarre reason, it is not allowed on events. I am using VS 2003, if that makes any difference. The only thing I can think of is to wrap all the events in a...
1
3137
by: Eric | last post by:
Hi, I have a WS client. All the code is generated by VS.NET 2003. For me its seems that an attribute is not generated during sending the request in the SOAPHeader. The problem is with RFCSendingValue. There the attribute 'groupeid0 isn't generated in the SOAP request.
2
1921
by: Dennis C. Drumm | last post by:
Is there a way to open files with .net 1.1 versions of my software product that were serialized with a .net 2.0 version of same product? Right now, as soon as my older .net 1.1 application tries to read the stream, an exception is thrown. The code to read the stream looks like this: BinaryFormatter bf = new BinaryFormatter();...
2
933
by: Karl | last post by:
Given: // A test object that needs to be serialized. public class TestSimpleObject { What attribute should I use if I wanted to serialize the above as simply
3
5316
by: CindyRob | last post by:
I am using .NET framework 1.1 SP1, .NET framework SDK 1.1 SP1, with hotfix 82202, Visual studio .NET 2003 with hotfix 823639. I have generated a proxy class using wsdl.exe from a schema that has an xsd:date element called XYZ_IncDate. <xsd:attribute name="XYZ_IncDate" type="xsd:date" use="required"> If I change the xsd:date element to be...
0
6590
by: bharathreddy | last post by:
Before going to that i want to say few thing on serialization : Serialization is the process of converting an object into a form that can be readily transported. For example, you can serialize an object and transport it over the Internet using HTTP between a client and a server. On the other end, deserialization reconstructs the object from the...
0
7276
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...
0
7182
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...
0
7581
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...
1
7142
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...
0
7548
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 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...
0
5714
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...
0
4773
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...
0
3267
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
488
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...

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.