我正在尝试创建一个具有 ArrayList 的类。例如:
public class SubCategory {
protected String nameOfCategory;
@XmlElement(required = true)
protected String link;
@XmlElementRef
protected List<SubCategory> supCategory;...
}
如何获取子类别的最后一个列表?我将 JAXB 用于 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>