我一直试图在 java 脚本中获取标签名称及其值。我使用的 xml 文件如下所示:
<root>
<note>
<to>Gil</to>
<from>
<firstname>john</firstname>
<lastname>corner</lastname>
</from>
<heading>Reminder</heading>
</note>
<note>
<to>Mary</to>
<from>
<firstname>Clara</firstname>
<lastname>Diana</lastname>
</from>
<heading>
How are you
</heading>
</note>
</root>
我希望输出如下:
TageName : root Attribute: 0 Text: null
TageName : note Attribute: 0 Text: null
TageName : to Attribute: 0 Text: Gil
TageName : from Attribute: 0 Text: null
TageName : firstname Attribute: 0 Text: john
TageName : lastname Attribute: 0 Text: corner
TageName : heading Attribute: 0 Text: Reminder
TageName : note Attribute: 0 Text: null
TageName : to Attribute: 0 Text: Mary
TageName : from Attribute: 0 Text: null
TageName : firstname Attribute: 0 Text: Clara
TageName : lastname Attribute: 0 Text: Diana
TageName : heading Attribute: 0 Text: How are you
这可能吗。如果是这样,请帮助我...