0
votes

Come to here to ask for litle help if someone know work with Jaxb technology. I want achieve generate XML with Marshaller.JAXB_SCHEMA_LOCATION and this create something like this

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="Document.xsd"

and i want omit this xsi:schemaLocation= "Document.xsd" element, so far i didnt find any solution, and also nowhere wasnt mentioned any similar situation how can it be edited this generated tag. is here someone to know any steps how can it be done? thanks a lot for help.

Cheers

1
Your question confuses me. You say that you add schemaLocation using the appropriate Marshaller property and then you ask how to remove it. What result are you trying to achieve? - bdoughan
Hi, marshaller with jaxb_schema_location generate me full schema like above but what i want is remove ** xsi:schemaLocation= "Document.xsd"** element from it,so far i didnt find any way do it to required state,thanks for any help - user3069432

1 Answers

0
votes

The only reason to set the Marshaller.JAXB_SCHEMA_LOCATION property is to have it appear in the XML that is marshalled. If you do not want it to appear then you need to not set that property.


UPDATE

because i have some specification where that property xsi:schemaLocation= "Document.xsd" cannot be shown so final tag must look like ; so far without any success

Based on this comment, I believe you are looking for information on how to namespace qualify your model. Below is an example.

Java Model

package-info

@XmlSchema(
    namespace="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03",
    elementFormDefault=XmlNsForm.QUALIFIED,
    xmlns={
        @XmlNs(prefix="", namespaceURI="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03"),
        @XmlNs(prefix="xsi", namespaceURI="http://www.w3.org/2001/XMLSchema-instance")
    }
)
package forum20397718;

import javax.xml.bind.annotation.*;

Document

package forum20397718;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="Document")
public class Document {

}

Demo Code

Demo

package forum20397718;

import javax.xml.bind.*;

public class Demo {

    public static void main(String[] args) throws Exception {
        JAXBContext jc = JAXBContext.newInstance(Document.class);

        Document document = new Document();

        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(document, System.out);
    }

}

Output

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>

For More Information