Search code examples
xmlliquid-xml

LiquidXML DataBinding Suppress NodeType when exporting to XML String


I use LiquidXML. I have a XSD file, this XSD File created a Visual Basic .Net project via the DataBinder tool. Now I create the classes and export them via xxx.ToXML The created Xml string looks good so far. But I get some of the nodes like this:

<pair>
            <patient xs:type="Patient">
                <id memberShipID="1"/>
                <name>xxx </name>
            </patient>

How can I create the export that way, that the patient node does NOT include the xs:type="Patient" NodeType?

THX a lot in advance


Solution

  • You need to set the WriteTypeAttribute to False in the Default XmlSerializationContext:

    VB .Net

    LiquidTechnologies.Runtime.Net45.SerializationContext.Default.WriteTypeAttribute = False
    

    C#

    LiquidTechnologies.Runtime.Net45.SerializationContext.Default.WriteTypeAttribute = false;
    

    C++

    LtXmlLib16::CSerializationContext::GetDefaultContext().SetWriteTypeAttribute(false);
    

    Java

    com.liquid_technologies.ltxmllib16.SerializationContext.Default.setWriteTypeAttribute(false);
    

    Please note the generator only adds xsi:type for derived types. Depending on your XML Schema, the xsi:type may need to be present in the XML Document in order for a parser to know which derived item is been used. This is described in the article 'Using the xsi:type Attribute'.