0
A
回答
4
您可以尝试JAXB
(XML绑定的Java架构)API。看看样品:
xml文件
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Child>
<foo>10</foo>
</Child>
<Child>
<foo>20</foo>
</Child>
</Root>
的Java的POJO表示XML架构
@XmlRootElement(name="Root")
class Bar{
private List<Foo> list=new ArrayList();
@XmlElement(name="Child")
public List<Foo> getList(){ return list;}
}
class Foo{
private Integer foo;
public Foo(){ foo=0;}
public Foo(Integer foo) { this.foo=foo;}
public Integer getFoo() { return foo; }
public void setFoo(Integer foo){ this.foo=foo;}
}
来读取XML的Java对象
JAXBContext context=JAXBContext.newInstance(Bar.class);
Unmarshaller um=context.createUnmarshaller();
Bar bar=(Bar)um.unmarshal(new File("x:\\path\\xmldoc.xml")); // you may specify the URL too.
System.out.println(bar.getList());
for(Foo c:bar.getList()){
System.out.println(c.getFoo());
}
+0
谢谢!我得到它的工作!自从我使用JDK 1.5以来,我现在使用JAXB并下载了所需的jar。顺便说一下,你还可以回答我的其他问题(这是关于JAXB):http://stackoverflow.com/questions/11425109/how-to-include-the-soap-envelope-tag-when-marshalling-using-jaxb ? – Arci 2012-07-11 03:29:50
相关问题
- 1. 像这样解析XML
- 2. Php SOAP解析器
- 3. simplexml无法像这样解析xml吗?
- 4. 解析与GSON
- 5. 如何使用Gson解析这个Json?
- 6. 是否有像HtmlAgilityPack(.NET)for Python这样的好解析器?
- 7. 有没有Java解析器,可以解析这样的地址
- 8. 用Gson解析JSON
- 9. GSON解析阵列
- 10. JSON解析与GSON
- 11. Android - JSON/GSON解析
- 12. 解析SOAP XML
- 13. Android的SOAP解析
- 14. GSON解析索引的JSON
- 15. 使用Gson的JSON解析
- 16. 无法解析转换器-gson包
- 17. Android gson流解析器或android.util.jsonreader?
- 18. java.lang.NoClassDefFoundError:解析失败:Lcom/google/gson/Gson;
- 19. 我想分析这与Gson
- 20. 使用Gson解析json java
- 21. GSON - 忽略解析异常
- 22. Gson(Json)解析异常
- 23. Android Json与GSON解析?
- 24. 使用GSON解析JSON
- 25. JSON解析与凌空GSON
- 26. Gson:解析泛型集合
- 27. 使用GSON解析长JSON
- 28. GSON JSON解析返回null
- 29. 同名字段GSON解析
- 30. 用gson解析JSON数组
你试过'DOM' ,'SAX'? – adatapost 2012-07-09 02:45:50
是的。但是它没有类似于Json的东西,其中bean的字段自动映射到bean。 – Arci 2012-07-09 02:51:21
要使用SOAP,您应该使用Web服务工具包(如JAX-WS)。这是一个相当重量级的解决方案,但该工具包应该能够为您生成大部分支持代码。 – millimoose 2012-07-09 07:07:26