ArrayListを持つクラスを作成しようとしています。例えば:
public class SubCategory {
protected String nameOfCategory;
@XmlElement(required = true)
protected String link;
@XmlElementRef
protected List<SubCategory> supCategory;...
}
サブカテゴリの最後のリストを取得するにはどうすればよいですか?JAXB for xmlファイルを使用していますが、xsdファイルは次のようになっています。
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/CategoriesTree" xmlns="http://www.example.org/CategoriesTree"
elementFormDefault="qualified">
<xs:element name="Categories">
<xs:complexType>
<xs:sequence>
<xs:element name="mainCategory" type="subCategory" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="subCategory">
<xs:sequence>
<xs:element name="nameOfCategory" type="xs:string"/>
<xs:element name="link" type="xs:string"/>
<xs:element name="subCategory" type="subCategory" maxOccurs="unbounded"
minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
はい、私はこのメソッドを持っていますが、たとえばツリーの最後の要素に移動する必要があります:最後の要素を取得する方法は?
<code>
<subCategory>
<nameOfCategory>Ordnungsmittel / Ablagemittel</nameOfCategory>
<link>link=Ordnungsmittel / Ablagemittel</link>
<subCategory>
<nameOfCategory>Ordnungsmittel / Ablagemittel</nameOfCategory>
<link>link=Ordnungsmittel / Ablagemittel</link>
<subCategory>
<nameOfCategory>Last</nameOfCategory>
<link>link=Last</link>
</subCategory>
</subCategory>
</subCategory>
</code>