xml.getChildCount returns wrong value

edited February 2017 in Questions about Code

Hi, this xml file:

<?xml version="1.0" encoding="UTF-8"?>
    <Structure>
      <Start x="0" y="0"/>
      <Goal x="100" y="100"/>
      <Blocks>
        <_0 x="250" y="100"/>
        <_1 x="250" y="150"/>
        <_2 x="250" y="200"/>
        <_3 x="250" y="250"/>
        <_4 x="250" y="300"/>
      </Blocks>
    </Structure>

with this source code:

XML xml, blocks;

void setup() {

  xml = loadXML("level.xml");
  blocks = xml.getChild("Blocks");

  println(blocks.getChildCount());
}

returns 11 in the console. But the tag "Blocks" just has 5 child elements. What am I doing wrong?

Answers

  • Forgetting about the whitespace.

  • if you iterate over the children printing each out (with suitable delimiters like "[" + value + "]") i think you'll see.

Sign In or Register to comment.