Get all nodes along the YAML path

I have a YAML file that looks like this:

Main: topofhouse: x: 276.4375 y: 71.0 z: -60.5 yaw: -290.7768 pitch: 35.400017 2ndfloor: x: 276.5 y: 67.0 z: -60.5 yaw: -8.626648 pitch: 16.199997 home: x: 276.5 y: 63.0 z: -60.5 yaw: -18.976715 pitch: -32.850002 

Is there a way to get all nodes under Main ?

+4
source share
1 answer

To get the node identifiers contained in Main :

 file.getConfigurationSection("Main").getKeys(false); 

Conclusion:

 Set["topofhouse", "2ndfloor", "home"] 

The ConfigurationSection.getConfigurationSection(String path) method is used to get the path to work.

The ConfigurationSection.getKeys(boolean deep) method will provide you with all node identifiers in the current path as Set<String> . If the deep parameter is set to true , it will also receive all nodes in the child and child elements, however, all relationships between them will be lost.

+5
source

Source: https://habr.com/ru/post/1400744/


All Articles