xmlファイルからスキーマファイルxsdから生成されたクラスへのバインディングデータを使用してオブジェクトを作成しようとしていますが、nullが発生します。
これが私のxsdで、そこからJavaクラスを生成しました。
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="people">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="employee"/>
<xsd:element ref="customer"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="employee">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref='name'/>
<xsd:element ref='country'/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name='name'>
<xsd:complexType>
<xsd:sequence>
<xsd:any namespace='http://www.w3.org/namespace/'/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name='country'>
<xsd:complexType>
<xsd:sequence>
<xsd:any namespace='http://www.w3.org/namespace/'/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="customer">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref='cname'/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name='cname'>
<xsd:complexType>
<xsd:sequence>
<xsd:any namespace='http://www.w3.org/namespace/'/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
私のXMLファイル:
<?xml version="1.0" encoding="UTF-8"?>
<people>
<employee>
<name>John</name>
<country>India</country>
</employee>
<customer>
<cname>steve</cname>
</customer>
</people>
そしてここで、xmlデータをjavaオブジェクトにバインドしようとしているが、nullを与えている私のコード:
File file = new File("D:\\file.xml");
JAXBContext jaxbContext = JAXBContext.newInstance("com.jaxb.xmlbinding");
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
People element = (People) jaxbUnmarshaller.unmarshal(file);
System.out.println(element.getEmployee().getName().getAny()); //giving null
誰か助けてくれませんか…。