开发者

JAXB value of a complex type

开发者 https://www.devze.com 2023-03-03 08:45 出处:网络
**Edit - in the end I removed the abstract extension to get this to function,the answer below from Blaise then works

**Edit - in the end I removed the abstract extension to get this to function, the answer below from Blaise then works

Hello.

I have a complex type in my schema:

<xs:complexType name="AbstractWorkflow" abstract="true">
    <xs:attribute name="id" type="xs:ID" use="required"/>
</xs:complex开发者_StackOverflow社区Type>
<xs:complexType name="ProcessWorkflow" mixed="true">
    <xs:complexContent>
        <xs:extension base="AbstractWorkflow"/>
    </xs:complexContent>
</xs:complexType>

The input to be unmarshalled is this

<ns1:Workflow stb:id="Workflow" xsi:type="ns1:ProcessWorkflow">workflowHTML.xml</ns1:Workflow>

But when I do this I get no option to access the value: workflowHTML.xml from the classes that have been generated from xjc. This is the start of the generated AbstractWorkflow class is there an annotation that I can declare in this class, that extends an abstract class, to specify that it is an element that carries a value itself? Shoud it not be declared as a FIELD or?

Edit it is the extending class that I need to implement the reading of a value not the abstract class that I had here originally.

@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
@XmlType(name = "ProcessWorkflow")
public class ProcessWorkflow
    extends AbstractWorkflow
{



}

Thanks for reading.


I believe you are looking for the @XmlValue annotation.

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Foo {

    @XmlAttribute
    private int id;

    @XmlValue
    private String value;

}

The above corresponds to the following XML schema:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="foo" type="foo"/>

  <xs:complexType name="foo">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="id" type="xs:int" use="required"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:schema>

And XML like this:

<foo id="123">Some Value</foo>
0

精彩评论

暂无评论...
验证码 换一张
取 消