Liquid XML Data Binder (C++, Java, VB6) / Using the Code / Changing the exported XML / Removing Optional Attribute Default values from the exported XML.
In This Topic
    Removing Optional Attribute Default values from the exported XML.
    In This Topic

    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 SerializationContext.

    Sample Code

      C++

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

      C#

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

      Java

    com.liquid_technologies.ltxmllib20.SerializationContext ctx = com.liquid_technologies.ltxmllib20.SerializationContext.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 = LtXmlComLib20.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