0

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>
3
  • 2
    I can't even tell what you're asking. Commented Nov 5, 2012 at 20:46
  • 1
    You might want to edit your question and tell us exactly what you're trying to do and what problem you're facing. The way it stands right now, I don't think anyone can decipher what your requirements are Commented Nov 5, 2012 at 20:49
  • @Sam I am Editet once again. Now I hope is ok. Commented Nov 5, 2012 at 21:27

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I check and all the time is problem. doc.getDocumentElement().getChildNodes().item(t).getFirstChild().getNodeValue().length()
I can`t using Tag name because I never know how will look like my xml tree -> but I start thinking one more time about lenght and now is working -> if(doc.getDocumentElement().getChildNodes().item(t).getChildNodes().getLength() >=1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.