how can I traverse through all ul and li elements in a tree structure :

<ul>
<li><a href="#">Places</a>
<ul>
<li><a href="#">Mercury</a></li>
<li><a href="#">Venus</a></li>
<li><a href="#">Earth</a></li>
</ul>
</li>

<li><a href="#">Google</a>
<ul>
<li><a href="#">Search</a></li>
<li><a href="#">News</a></li>
</ul>
</li>
.
.
.
</ul>

I want to get all values in ul and li tags in java script.