In this short how-to guide we will show you how to reference a schema in schemaLocation, the settings that need to be changed and their effects of the generated result.
The xsi:schemaLocation attribute locates schemas for elements and attributes that are in a specified namespace. Its value is
is a sequence of alternating namespace URI's followed by relative or absolute URL's where the schema for that namespace can be found.
An XML documents can be linked with their schemas using the schemaLocation attribute. It is most commonly attached to the root element but can appear further down the tree.
This information may identify the location of the associated schemas, as well as further identify the schema types used, which opens a new level of flexibility and interaction between schemas and instance documents in the design of XML applications.
In order for the XML serialization process to produce this attribute, the following must settings must be set :
In the xsd2code++ settings, you can specify the SchemaLocation. This option can be found in the Serialization, XmlOuput, SchemaLocation section.
Of course it is necessary to enable the generation of XML attributes in the section "Output property settings", you need to set the XmlAttribute.Enabled setting to true.
The code that will be generated will contain an additional public variable in each of the classes so that the serialization makes the expected attribute:
<?xml version="1.0" encoding="utf-8"?> <MyObject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:SchemaLocation="http://www.w3.org/2001/XMLSchema-instance" xmlns="MyObject.MemoryLayout"> <FileInformation dateTimeCreated="0001-01-01T00:00:00" dateTimeChanged="0001-01-01T00:00:00" xmlns="AllegroMicro.Common"> <Description>Test</Description> </FileInformation> </MyObject>
And that is how you reference a schema in SchemaLocation. Have fun !
CodeNGine Technologies, 19 Avenue, de la gare, 34770 Gigean, France. SIRET: 85257252800010, VAT : FR 62852572528
About the company
CodeNGine Technologies is software company based in the South of France that provides an advanced productivity code generation tool to developers using XML and JSON
Copyright © 2021 CodeNGine Technologies