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
![]() ![]() |
---|
CLtXmlLib20::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")); |
![]() ![]() |
---|
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"); |
![]() ![]() |
---|
import com.liquid_technologies.ltxmllib20; ... SerializationContext.Default.getAdditionalRootAttributes.add( "schemaLocation", "http://www.example.com/Report http://www.example.com/Report.xsd", "http://www.w3.org/2001/XMLSchema-instance"); |
![]() ![]() |
---|
LtXmlComLib20.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 | |
Hand Coded Blocks |