XML getChildren() every even child is empty

Hello,

I am working with some XML data, and I stumbled upon some rather interesting behavior.

Sketch:

XML xml = loadXML("xml.xml");

printArray(xml.getChildren());
println("-----");

XML[] children = xml.getChildren();

for (int i = 0; i < children.length; i++) {
  println(children[i] + ":");
  XML[] rows = children[i].getChildren();
  for (int r = 0; r < rows.length; r++) {
    println("  row " + r + " '" + rows[r] + "'" +":");
    XML[] cols = rows[r].getChildren();
    for (int c = 0; c < cols.length; c++) {
      println("    col " + c + " '" + cols[c] + "'");
    }
  }
}

xml.xml:

<?xml version="1.0"?>

<node>
    <table>
        <row>
            <col>1,1</col>
            <col>1,2</col>
        </row>
        <row>
            <col>2,1</col>
            <col>2,2</col>
        </row>
        <row>
            <col>3,1</col>
            <col>3,2</col>
        </row>
    </table>
</node>

Output:

[0] 
[1] <table><row><col>1,1</col><col>1,2</col></row><row><col>2,1</col><col>2,2</col></row><row><col>3,1</col><col>3,2</col></row></table>
[2] 
-----
:
<table><row><col>1,1</col><col>1,2</col></row><row><col>2,1</col><col>2,2</col></row><row><col>3,1</col><col>3,2</col></row></table>:
  row 0 '':
  row 1 '<row><col>1,1</col><col>1,2</col></row>':
    col 0 ''
    col 1 '<col>1,1</col>'
    col 2 ''
    col 3 '<col>1,2</col>'
    col 4 ''
  row 2 '':
  row 3 '<row><col>2,1</col><col>2,2</col></row>':
    col 0 ''
    col 1 '<col>2,1</col>'
    col 2 ''
    col 3 '<col>2,2</col>'
    col 4 ''
  row 4 '':
  row 5 '<row><col>3,1</col><col>3,2</col></row>':
    col 0 ''
    col 1 '<col>3,1</col>'
    col 2 ''
    col 3 '<col>3,2</col>'
    col 4 ''
  row 6 '':
:

As you can see, this yields some strange results, where every even array index is empty. This happened to me when I was drawing such a table using index numbers, and totally broke my sketch. What could be causing this?

Answers

Sign In or Register to comment.