2017-01-13 63 views
0

是否有人知道如何將屬性的值映射到字段。說郎標籤,這是「SW」到現場一類使用MOXy在XML中提取屬性值

<book category="cooking"> 
     <title lang="sw">Vegetarian</title> 
     <year>2008</year> 
     <price>30.00</price> 
     <authors> 
      <author>Tichaona</author> 
      <author>Ngodza</author> 
     </authors> 
    </book> 

...... 
...... 
...... 

<book category="Huffman Coding"> 
     <title lang="en">Encryption</title> 
     <year>2000</year> 
     <price>45.00</price> 
     <authors> 
      <author>Ruvimbo</author> 
     </authors> 
    </book> 

我希望能夠在屬性郎值投入使用莫西擴展字段的值。沿

@XmlPath("title/@lang") 
private String language; 

誰能幫

回答

1

假設你有莫西設置正確的線路比較多,我想你會與你的榜樣的問題是與XPath "title/@lang"實際上不會解決到屬性你想要。

//title/@lang這樣的東西應該做選擇lang屬性值的技巧。

+0

感謝克里斯蒂,我想知道爲什麼它需要2個正斜槓。我會嘗試。 – ngonidzashe

+0

單個正斜槓用於根,雙意味着它將搜索不僅僅是直接孩子的元素。如果你需要那些使用Moxy的人,我實際上並不是100%確定的,但我會假設這條道路是相對於被編組的班級的根源的 – Christy