Rudziankoŭ
Rudziankoŭ

Reputation: 11251

How I can extract parameters from xml?

How I can extract value Total topics?

<?xml version="1.0"?>
<config>
<command param = "Total topics" > Check title
</command> 
</config>

I know that for extracting value of Check title I need such code:

XPathExpression  expr = xpath.compile("//command/text()");
Object result = expr.evaluate(doc, XPathConstants.NODESET);

Help me with param, please.

Upvotes: 0

Views: 148

Answers (2)

RST_7
RST_7

Reputation: 86

XPathExpression  expr = xpath.compile("//command[@param]/text()");
Object result = expr.evaluate(doc, XPathConstants.NODESET);

I've not compiled it but to select an attribute you'll need to used @attributeName after the node is selected.

Upvotes: 1

Pshemo
Pshemo

Reputation: 124255

How about using @ for attribute? Try with

XPathExpression  expr = xpath.compile("//command/@param");

Upvotes: 0

Related Questions