【发布时间】:2016-01-05 19:48:23
【问题描述】:
我有一个 XML 文件,格式如下:
<head>
<username>bhnsub</username>
<error>0</error>
<account_id>633</account_id>
<info>
<mac>address_goes_here<mac>
<mac>address_goes_here</mac>
<mac>address_goes_here</mac>
<mac>address_goes_here</mac>
<mac>address_goes_here<mac>
</info>
</head>
我需要使用 Java DOM 解析器对其进行解析并获取相应的值。 我需要将信息下的值放在列表中。
SAXBuilder builder = new SAXBuilder();
Document document = (Document) builder.build(new StringReader(content));
Element rootNode = document.getRootElement();
if (rootNode.getName().equals("head")) {
String username = rootNode.getChildText("username");
String error= rootNode.getChildText("error");
String account= rootNode.getChildText("account_id");
Element info= rootNode.getChildren("info");
List mac=info.getChildren("mac");
我不知道如何继续使用该列表。
【问题讨论】:
标签: java xml xml-parsing jdom