6

This question is following on from Blaise's excellent answer here.

My question is, how do I use the JAXB @XmlSchema annotation from within Scala?

This is what I've come up with so far:

// File src/main/scala/co/orderly/prestasac/representations/wrappers.scala
package co.orderly.prestasac.representations

// JAXB
import javax.xml.bind.annotation._

@XmlSchema(xmlns = Array(@XmlNs(prefix = "xlink", namespaceURI = "http://www.w3.org/1999/xlink")))
package object wrappers {
}

Unfortunately this throws an error:

/home/alex/Development/Orderly/prestashop-scala-client/src/main/scala/co/orderly/prestasac/representations/wrappers/wrappers.scala:18: illegal start of simple expression
[error] @XmlSchema(xmlns=Array(@XmlNs(prefix = "xlink", namespaceURI = "http://www.w3.org/1999/xlink")))
[error]                        ^    

In case there's a workaround which doesn't require @XmlSchema, I'll explain what I'm trying to do - basically I'm trying to unmarshall an XML representation which looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<products>
<product id="11" xlink:href="http://www.myshop.com/api/products/11"/>
<product id="12" xlink:href="http://www.myshop.com/api/products/12"/>
...
</products>
</prestashop>

I believe I need to use @XmlSchema to define the "xlink"-prefixed namespace for the href links...

Community
  • 1
  • 1
Alex Dean
  • 15,575
  • 13
  • 63
  • 74
  • 1
    Have you tried using `new XmlNs` instead of `@XmlNs` for the nested annotations? – Jean-Philippe Pellet Dec 20 '11 at 10:01
  • Thanks Jean-Philippe - `new XmlNs` definitely helps: the error shown above goes away, but I'm left with `expected start of definition` on the start of the `package object wrappers` line... – Alex Dean Dec 24 '11 at 19:05
  • 3
    Update: it looks like this is not currently possible with Scala: https://issues.scala-lang.org/browse/SI-3600 However, resorting to a `package-info.java` file in the appropriate place inter-ops fine with Scala – Alex Dean Dec 27 '11 at 11:12

0 Answers0