Liquid XML Data Binder 2020
Liquid XML Data Binder (C++, Java, VB6) / Using the Code / Changing the exported XML / How Do I Add Root Level Attributes?
In This Topic
    How Do I Add Root Level Attributes?
    In This Topic

    How Do I Add Root Level Attributes?

    Problem

    It is sometimes necessary to add additional attributes to the root element, a good example is the schemaLocation attribute which indicates where the schema that validates the document can be found.

    Resolution

    The code below demonstrates how to insert the schemaLocation item into the root element

    <?xml version="1.0"?> <purchaseReport xmlns="http://www.example.com/Report"                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"                 xsi:schemaLocation="http://www.example.com/Report                 http://www.example.com/Report.xsd">         ... </purchaseReport>

    Sample Code

      C++

    CLtXmlLib18::CSerializationContext::GetDefaultContext() .GetAdditionalRootAttributes()->Add( _T("schemaLocation"), _T("http://www.example.com/Report http://www.example.com/Report.xsd"), _T("http://www.w3.org/2001/XMLSchema-instance"));

      C#

    using LiquidTechnologies.Runtime.Net40; ... SerializationContext.Default.AdditionalRootAttributes.Add( "schemaLocation", "http://www.example.com/Report http://www.example.com/Report.xsd", "http://www.w3.org/2001/XMLSchema-instance");

      Java

    import com.liquid_technologies.ltxmllib18; ... SerializationContext.Default.getAdditionalRootAttributes.add( "schemaLocation", "http://www.example.com/Report http://www.example.com/Report.xsd", "http://www.w3.org/2001/XMLSchema-instance");

      Visual Basic

    LtXmlComLib18.DefaultXmlSerializationContext.AdditionalRootAttributes.AddNewEx _ "schemaLocation", _ "http://www.w3.org/2001/XMLSchema-instance", _ "http://www.example.com/Report http://www.example.com/Report.xsd"

     

    Notes

    Descrption Value
    Article Created 7/2/2006
    Versions Liquid XML 2005 (4.1.0) and greater
    Also See Setting A Default Namespace
      Working In a multithreaded environment
     

    Working With Multiple Schemas

      Hand Coded Blocks