java - How to get only first level nodes with Jsoup -


i have following xml tree , i'm using jsoup parse it.

<?xml version="1.0" encoding="utf-8" ?> <nodes>     <node>         <name>node 1</name>         <value1>             <value1>node 1 value 1</value1>         </value1>         <nodes>             <node>                 <name>node 1 child</name>                 <value1>node 1 child value 1</value1>             </node>         </nodes>     </node>     <node>         <name>node 2</name>         <value1>node 2 value 1</value1>     </node> </nodes> 

however when try first level of node-elements. returns elements including children nodes, , doing correctly, because child elements match query.

elements elements = data.select("nodes > node"); 

is there way first level node-elements without adding additional level information xml data?

you can this:

elements elements = data.select("nodes").first().select("> node"); 

this work well:

elements elements = data.select("> nodes > node"); 

but if you've used jsoup.parse(xml, "", parser.xmlparser()) parse xml , xml indeed you've specified in question (<nodes> root element)


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -