Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] [Repost Bug] null children of parentNode

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Peter Murray-Rust <pm286 AT cam.ac.uk>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] [Repost Bug] null children of parentNode
  • Date: Sat, 5 Sep 2009 12:07:25 +0100

I have isolated the problem with insertChild and am now running the latest
(today, 1.2.2 version of XOM). The following code allows the insertion of a
child beyond child count and fills the intervening children as nulls:

import java.io.IOException;

import nu.xom.Document;
import nu.xom.Element;
import nu.xom.Serializer;

public class TestXOM {

public static void main(String[] args) {
Element parent = new Element("p");
for (int i = 0; i < 3; i++) {
Element c = new Element("c");
parent.appendChild(c);
}
System.out.println(parent.getChildCount());
Element d = new Element("d");
// should this throw an IndexOutOfBoundsException -
// if the position is negative or greater than the number of
children of this node
parent.insertChild(d, 5);
System.out.println(parent.getChildCount());
System.out.println(parent.getChild(3));
Serializer s = new Serializer(System.out);
try {
s.write(new Document(parent));
} catch (IOException e) {
e.printStackTrace();
}
}

}

gives:

3
4
null
Exception in thread "main" java.lang.NullPointerException
at nu.xom.Serializer.writeChild(Unknown Source)
at nu.xom.Serializer.write(Unknown Source)
at nu.xom.Serializer.writeChild(Unknown Source)
at nu.xom.Serializer.write(Unknown Source)
at testxom.TestXOM.main(TestXOM.java:26)

If this is not a bug, please let me know what I am doing wrong.

TIA

P.


--
Peter Murray-Rust
Reader in Molecular Informatics
Unilever Centre, Dep. Of Chemistry
University of Cambridge
CB2 1EW, UK
+44-1223-763069




Archive powered by MHonArc 2.6.24.

Top of Page