こんにちは私は、Webサービスから生成された次の形式のxmlを持っています。どのようにJavaオブジェクトにXMLを解析するのですか?
<root>
<item>
<name>test</name>
<description>test description</description>
<link>http://xxx</link>
</item>
</root>
私は今、私は私が取得し、各
のためだろうかドキュメントを、持っていると、オブジェクト呼び出し項目
public class Item {
private final String name;
private final String desc;
private final String link;
public Item(final String name, final String desc, final String link) {
super();
this.name = name;
this.desc = desc;
this.link = link;
}
// ... getters for name and desc
}
にそれを置くことを、ファイル
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new URL(url).openStream());
を読みます
私はdom要素の例を見ていますが、混乱しているようです。 XMLをjavaオブジェクトに解析する最も簡単で効果的な方法は何ですか?私は例を得ることができますか?
xstreamを使用すると動作します。
私は、XMLをJavaオブジェクトに解析することができます
final XStream xstream = new XStream(new DomDriver());
xstream.alias("root", LineItem.class);
xstream.aliasField("name", Item.class, "name");
xstream.aliasField("description", Item.class, "desc");
xstream.aliasField("link", Item.class, "link");
xstream.fromXml(xml);
どのプログラミング言語を使用していますか? Javaの場合、JAXBを使用できます。ここでは良い例のリンクはありますか? http://www.javabeat.net/articles/14-java-60-features-part-2-pluggable-annotation-proce-3.html – kosa