Rafał Developer
Rafał Developer

Reputation: 2055

Java - xml list or one value

What I have to do to check I have got list of data or one argument?

I have got this in code software and he show "yes" if argument 1 but if I have got list I have got empty place. I would like to make If which can accept only one agument but no list.

System.out.println(doc.getDocumentElement().getChildNodes().item(t).getNodeName());    
System.out.println(doc.getDocumentElement().getChildNodes().item(t).getLastChild().getNodeValue());

Output (because car have list of nodes and If some element have list not one value I don`t want to show this element for example "car"):

Adam
yes
car

List:

<car>
<window>yes</window>
<door>yes</door>
</car>

1 argument

<Adam>yes</Adam>

Upvotes: 0

Views: 248

Answers (1)

forty-two
forty-two

Reputation: 12817

Just check the length of the list.

And you probably don't want all kinds of child nodes, rather just child elements. Try

doc.getDocumentElement().getElementsByTagName("*")

instead.

Upvotes: 1

Related Questions