首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用JAVA连接.xml文件中的多个标记

使用JAVA连接.xml文件中的多个标记
EN

Stack Overflow用户
提问于 2018-05-27 22:27:16
回答 2查看 455关注 0票数 1

我想使用JAVA连接来自xml文件的多个标记值。.xml如下所示:

代码语言:javascript
运行
复制
<test>
    <testcase>
        <teststep> row 1 </teststep>
        <teststep> row 2 </teststep>
        <teststep> row 3 </teststep>
        <title> Frist Test </title>
    </testcase>
</test>
<test>
    <testcase>
        <teststep> row 20 </teststep>
        <teststep> row 10 </teststep>
        <teststep> row 30 </teststep>
        <title> Second Test </title>
    </testcase>
</test>

结果应该是这样的:

代码语言:javascript
运行
复制
row 1 row 2 row 3
row 10 row 20 row 30

应该有两个变量。

我试过了:

代码语言:javascript
运行
复制
NodeList nodeList5 = doc.getElementsByTagName("teststep");
for (int x = 0, size = nodeList5.getLength(); x < size; x++) {
    description = description + nodeList5.item(x).getTextContent();
}
System.out.println("Test Description: " + description);

但是我得到的是:行1行2行3行10行20行30,只有一个变量。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50553142

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档