Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to avoid self-closing tags when using XML Serialization?

I am working with VB.NET and I am facing a problem with XML serialization. When empty values exists in the object I am serializing, the XML file contains the following tags:

<tagName/>

instead of:

<tagName></tagName>

I know that it's the same, but I want the start tag to close appropriately.

like image 472
Pan Avatar asked Feb 08 '11 10:02

Pan


People also ask

Does XML allow self closing tags?

In XML and XHTML, a self-closing tag is a shorthand notation for an opening and closing tag in one. It's used to communicate lack of content in between the opening and closing tags. So, rather than typing <p></p> (with no space at all in between), you'd be able write <p/> .

What is the correct way of using XML serialization?

XML serialization does not convert methods, indexers, private fields, or read-only properties (except read-only collections). To serialize all an object's fields and properties, both public and private, use the DataContractSerializer instead of XML serialization.

What is closing tag in XML?

The end tag functions exactly like a right parenthesis or a closing quotation mark or a right curly brace. It contains no data of its own; it simply ends the most recent (innermost) tag with the same name.

Which class should be used to serialize an object in XML format?

Xml. Serialization namespace) class is used to serialize and deserialize. The class method Serialize is called. Since we have to serialize in a file, we create a " TextWriter ".


1 Answers

They are the same and it makes no difference. Any parser or reader understands the meaning, so why is this so important to change?

I find the current behavior better as it will result in smaller files.

Regardless, there is no way to override this behavior.

like image 81
Oded Avatar answered Oct 20 '22 11:10

Oded