Question

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?

Was it helpful?

Solution

To get the node IDs contained in Main:

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

Output:

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

The ConfigurationSection.getConfigurationSection(String path) method is used to get the path on which to operate.

The ConfigurationSection.getKeys(boolean deep) method will get you all node IDs within the current path as a Set<String>. When deep is set to true, it will get all the nodes in the children and subchildren too, however, all relations between them will be lost.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top