How can I describe a reference in a node to another one?
I have an XML format I need to parse. An example file is listed below:
<?xml version="1.0" encoding="UTF-8">
<root>
<parent name="example1">
<childdef ref="1" type="a" />
<childdef ref="3" type="c" />
</parent>
<parent name="example2">
<childdef ref="1" type="b" />
<childdef ref="2" type="b" />
</parent>
<child id="1" name="Child 1" />
<child id="2" name="Child 2" />
<child id="3" name="Child 3" />
<child id="4" name="Child 4" />
</root>
The parent
elements contain at least one childdef
element that refers to a child element. You must use a reference, because one child can be referenced by several parents (see child 1).
If I now use an XML mapper (e.g. a JAXB implementation), I would like to have a Object refere开发者_StackOverflownce from Parent1 to Child 1. Now I only have the reference id as an attribute.
Is it possible to define this object reference in the XSD?
Yes, that's possible. See @XmlID
and @XmlIDREF
. They correspond to the XML types xsd:id
and xsd:idref
. But keep in mind that only strings can be IDs.
精彩评论