JAXB XJC code generation - "schemaLocation" missing in xml generated by Marshaller

18,779

Try this:

marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://my.namespace my.schema.xsd");
Share:
18,779
cubesoft
Author by

cubesoft

Software Developer and Freelancer

Updated on June 18, 2022

Comments

  • cubesoft
    cubesoft almost 2 years

    I Use XJC tool to generate Java classes for my XSD schema. When I use JAXB Marshaller to marshall classes into XML payloads, I'm missing "schemaLocation" parameter in the output XML, but I declare this parameter in xsd file. How to enforce "schemaLocation" parameter in the output XML?

    Below is the begining of my xsd schema file used for code generation:

    <?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="xsdns" xmlns:messages="http://www.exampleURI.com/Schema1" xmlns:datatypes="http://www.exampleURI.com/Schema1" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:schemaLocation="http://www.exampleURI.com/Schema1 ./messages.xsd" targetNamespace="http://www.exampleURI.com/Schema1" elementFormDefault="unqualified" version="true">
    <xs:include schemaLocation="datatypes.xsd"/>
    <xs:complexType name="execute-system-command-struct">
        <xs:annotation>
            <xs:documentation>The request for system command execution.</xs:documentation>
        </xs:annotation>
        <xs:sequence/>
        <xs:attribute name="action" type="datatypes:system-action-kind-enum" use="required">
            <xs:annotation>
                <xs:documentation>The action that the Voice System has to proceed.</xs:documentation>
            </xs:annotation>
        </xs:attribute>
    

    Regards