Tristan
Tristan

Reputation: 288

JAXB bindings exclude field

I've looked around google a little bit, but I'm sure someone here can provide the answer to this quicker than I can track it down. I'm running a XJC2Task (org.jvnet.jaxb2_commons.xjc.XJC2Task) with a binding.xjb file to generate java source from some XSDs.

We are looking at removing some personal information that we receive from a third party from the data. Is there a way that I could specify some of the elements as @XMLTransient or ignore them outright from the bindings.xjb file?

So for example If I have the following xsd :

    <?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="test.3.0" xmlns="test.3.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"  elementFormDefault="qualified" attributeFormDefault="unqualified">

    <xs:element name="TestInfo" type = "TestInfo">
        <xs:annotation>
            <xs:documentation>TestInfo schema</xs:documentation>
        </xs:annotation>
    </xs:element>
    <xs:complexType name="TestInfo">
        <xs:sequence>
            <xs:element name="name" type="xs:string" minOccurs="0"/>
            <xs:element name="id" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>

</xs:schema>

and in my binding.xjb file I have

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings version="2.1" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
               xmlns:xs="http://www.w3.org/2001/XMLSchema"
               xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
               jaxb:extensionBindingPrefixes="inheritance">

    <jaxb:globalBindings>
        <jaxb:serializable uid="1" />
    </jaxb:globalBindings>
    <jaxb:bindings schemaLocation="schema/test.xsd">
        <jaxb:schemaBindings>
            <jaxb:package name="org.test" />
        </jaxb:schemaBindings>
    </jaxb:bindings>

Is there a way that I can remove the id from this? I'm hoping I don't have to relearn XSLT to accomplish this. ;D

Upvotes: 3

Views: 4879

Answers (1)

Xstian
Xstian

Reputation: 8272

You can use this bindings using annox (jaxb2-basics-annotate).

<jaxb:bindings
  xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:annox="http://annox.dev.java.net"
  xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
  jaxb:extensionBindingPrefixes="xjc annox"
  version="2.1">

    <jaxb:bindings schemaLocation="schema/test.xsd">

        <jaxb:bindings
            node="//xs:complexType[@name='TestInfo']//xs:sequence//xs:element[@name='id']">
            <annox:annotate>
                <annox:annotate annox:class="javax.xml.bind.annotation.XmlTransient">
                </annox:annotate>
            </annox:annotate>
        </jaxb:bindings>

    </jaxb:bindings>
</jaxb:bindings>

Upvotes: 3

Related Questions