Using JAXB IDREF and ID?

I am looking to write an XSD that will be used to create some Java classes through JAXB. I want the resulting XML to look like this:

<Appointment>
    <Patient ref="12345">Bob Smith</Patient>
    <Type>Some Appointment Type</Type>
    <Date>2010-02-17</Date>
    ....
</Appointment>

So, given this diagram, I want it to create a class where I can just do something like this:

Patient p = loadPatientFromDB();
Appointment a = new Appointment();
a.setPatient(p);
a.setType("Some Appointment Type");

I think that what I want to do is to have an element that has IDREF as an attribute, and then a string as the contents of the element.

Can someone give me a hand with some of the XSD?

Thank!

EDIT

This question can also be asked as follows.

Can simpleType have an attribute or should it be complexType.

So can you

  <element id="foo">bar</element>

or do you have

  <element id="foo"><name>bar</name></element>
+3
source share
1 answer

, . , . , , :

<xs:complexType name="Person">
    <xs:simpleContent>
        <xs:extension base="xs:string">
           <xs:attribute name="ref" type="xs:IDREF" use="required"/>
        </xs:extension>
    </xs:simpleContent>
</xs:complexType>

: , "", <person id="foo">A Name</person>.

: , , . , . .

+4

Source: https://habr.com/ru/post/1733080/


All Articles