John Lippson
John Lippson

Reputation: 1319

Converting java object into XML?

I have a Java object and trying to achieve XML generation in the cleanest way possible.

Desired XML

<fes:PropertyIsLessThan matchAction="ANY" matchCase="false">

  <fes:ValueReference>name</fes:ValueReference>

  <fes:Function name="sub">

    <fes:Literal>my-id</fes:Literal>

  </fes:Function>

</fes:PropertyIsLessThan>

<fes:And>

  <fes:PropertyIsGreaterThanOrEqualTo matchAction="ANY" matchCase="false">

    <fes:ValueReference>attName</fes:ValueReference>

    <fes:Literal>5</fes:Literal>

  </fes:PropertyIsGreaterThanOrEqualTo>

  <fes:PropertyIsLike escapeChar="\" matchCase="false" singleChar="?" wildCard="*">

    <fes:ValueReference>title</fes:ValueReference>

    <fes:Literal>greetings</fes:Literal>

  </fes:PropertyIsLike>

</fes:And>

I'm using filter functions as found here: http://docs.geoserver.org/stable/en/user/filter/function.html

I see there is JaxB out there that may help with conversion of a POJO to XML. But what is out there to make this task fairly straight forward? I'm trying to understand the process of how a class can get converted to a valid XML like the following.

Upvotes: 0

Views: 97

Answers (1)

lexicore
lexicore

Reputation: 43709

Disclaimer: I'm the author of the OGC Schemas Project which compiles OGC Schemas for JAXB.

I guess you're using OGC Filter schema in one of the versions (probably 2.0). The OGC Schemas Project provides pre-compiled OGC Schemas, including Filter schemas.

In order to use it, import

<dependency>
    <groupId>org.jvnet.ogc</groupId>
    <artifactId>filter-v_2_0</artifactId>
    <version>2.6.1</version>
</dependency>

into your project. Then you could create a JAXBContext with the context path "net.opengis.filter.v_2_0:net.opengis.ows.v_1_1_0:org.hisrc.w3c.xlink.v_1_0". You could use this JAXBContext to unmarshal XML and marshal object structures.

Upvotes: 1

Related Questions