XMLStreamReaderを使用してネストされたXMLファイルをアンマーシャルしようとしています。私は、次のようなクラスを作成しているXSDを使用しないXMLStreamReaderを使用した複雑なネストされたXMLファイルのアンマーシャリング
<?xml version="1.0" encoding="UTF-8"?>
<tns:Envelope
xmlns:tns="http://www.w3.org/2003/05/soap-envelope-dial"
xmlns:lmic="http://www.example.com"
xmlns:producer="http://example1.com/"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:ns5="http://www.example.com/dial/3/0">
<tns:header>
...
...
</tns:header>
<tns:body>
<producer:Producer id="1234">
<producer:GenParty>
<producer:NameInfo>
<producer:Comm>
<producer:SuppName>DATA</producer:SuppName>
<producer:ContractNumber>123456</producer:ContractNumber>
</producer:Comm>
</producer:NameInfo>
<producer:Address>
<Street>ABC</Street>
<Country>DEF</Country>
...
...
</prodcer:Address>
<producer:Address>
<Street>ABC</Street>
<Country>DEF</Country>
...
...
</prodcer:Address>
</producer:GenParty>
</producer:Producer>
</tns:body>
</tns:emvelope>
:
@XmlRootElement(name="Producer",namespace="http://example.com/")
@XmlAccessorType(XmlAccessType.FIELD)
Class Producer {
private GenParty;
// getter method of class GenParty
// setter method of class GenParty
}
@XmlRootElement(name="GenParty")
@XmlAccessorType(XmlAccessType.FIELD)
class GenParty {
private NameInfo;
private List<Address> address;
//getter of both fields
// setter of both fields
}
を、後続のクラスが定義されています私のXMLファイルは、次のようになります。
私はタグに進めるためにXMLStreamReaderを使用していますし、私のように私のunmarshalerコードを書いています:
JAXBContext jc = JAXBContext.newInstance(Producer.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
Producer producer = unmarshaller.unmarshal(xsr,Producer.class).getValue();
しかし、私はプロデューサーのオブジェクト上に設定され、ヌル値を取得しています。私が間違っていることは何ですか?私は単純なXMLファイルを非整列化することができましたが、このレベルのネストは私にとって問題を作り出しています。誰かがそれをやり直すことを提案してもらえますか、私のコードスケルトンで何か変更を加えるべきですか?
ありがとうございます!
JAXBの名前空間が間違っているためですか? –
あなたのXMLは 'xmlns:producer =" http://example1.com/ "という名前空間を使いますが、Producerクラスは' namespace = "http://example.com/" ' –