Removing Optional Attribute Default values from the exported XML.

Problem

By default the liquid XML libraries insert default values into missing optional attributes into the XML that they export.
This is not always the required functionality, and omitting these values still provides a valid XML document.

Resolution

These values can be omitted from the Output XML, by setting the NoOptionalAttributeDefaultOutput Propery of the XmlSerializationContext.

Sample Code

  C++

LtXmlLib16::CXmlSerializationContext ctx = LtXmlLib16::CXmlSerializationContext::GetDefaultContext();
ctx.SetNoOptionalAttributeDefaultOutput(true);
std::tstring strXml = elm->ToXml(true, true, EOLType_LF, ctx);

  C#

LiquidTechnologies.Runtime.Net40.XmlSerializationContext ctx = LiquidTechnologies.Runtime.Net40.XmlSerializationContext.Default;
ctx.NoOptionalAttributeDefaultOutput = true;
string strXml = elm.ToXml(true, System.Xml.Formatting.Indented, LiquidTechnologies.Runtime.Net40.EOLType.CRLF, ctx);

  Java

com.liquid_technologies.ltxmllib16.XmlSerializationContext ctx = com.liquid_technologies.ltxmllib16.XmlSerializationContext.Default;
ctx.setNoOptionalAttributeDefaultOutput(true);
String strXml = elm.toXml(true, Formatting.Indented, Encoding.UTF8, EOLType.CRLF, ctx);

  Visual Basic

Dim ctx As XmlSerializationContext
Dim strXml As String
Set ctx = LtXmlComLib16.DefaultXmlSerializationContext
ctx.NoOptionalAttributeDefaultOutput = True
strXml = oElm.ToXml(True, XmlFormatting_Indented, EOLType_LF, ctx)

 

Notes

Description Value
Article Created 15/6/2006
Relates to Versions Liquid XML 2006 and greater