【发布时间】:2017-05-15 10:53:49
【问题描述】:
我想获取客户节点中的 id、年龄、姓名和客户节点中的 listType、联系人。
我的示例 Xml 格式是
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customers>
<values>
<type>
<customer id="100">
<age>29</age>
<name>mkyong</name>
</customer>
<customer id="140">
<age>29</age>
<name>chandoo</name>
</customer>
</type>
</values>
<listType>Population</listType>
<contact>phani</contact>
</customers>
我创建了以下 pojo 类(客户、价值、类型、客户)
Customers.java
@XmlRootElement( name="customers" )
public class Customers {
List<Values> values;
private String listType;
private String contact;
Setters & Getters
}
值.java
class Values {
List<Type> type;
Setters & Getters
}
Type.java
class Type {
private int id;
private List<Customer> customer;
Setters & Getters
}
客户.java
class Customer {
private String name;
private int age;
Setters & Getters
}
主类在 应用程序.java
public static void main(String[] args) {
try {
File file = new File("D:/userxml/complex.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(Customers.class,Values.class,Type.class,Customer.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Type type = (Type) jaxbUnmarshaller.unmarshal(file);
System.out.println(type);
} catch (JAXBException e) {
e.printStackTrace();
}
}
我是 PHP 开发人员,是 Java 新手。请帮帮我。我想获取客户详细信息
【问题讨论】:
-
你的问题是什么?
-
@BetaRide 我编辑了我的问题。您能提供此查询的帮助网址或答案吗? TQ
标签: java xml xml-parsing jaxb