Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] XPath Mapping on empty text nodes

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: shirasu hiroyuki <hirsh AT s9.dion.ne.jp>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] XPath Mapping on empty text nodes
  • Date: Fri, 28 Jan 2005 18:17:11 +0900 (JST)

Hello,

I read 'XOM XPath Mapping' at the XOM site, and have some
questions on empty text nodes. I tried the following test
case, in which a empty text node was followed by one text node.
I had the expected result with success.

public void testAdjacentTextNodes() {
Element parent = new Element("parent");
Text empty = new Text("");
Text nonempty = new Text("value");
parent.appendChild(empty);
parent.appendChild(nonempty);
Nodes result = parent.query("node()");
assertEquals(2, result.size());

Nodes result2 = parent.query("/*[count(node())=1]");
assertEquals(1, result2.size());
assertEquals(parent, result2.get(0));

Nodes nodes1 = parent.query("node()[1]");
assertEquals(2, nodes1.size());
Nodes nodes2 = parent.query("node()[2]");
assertEquals(0, nodes2.size());
}


So I tried two examples, in which a empty text node follows
one nonempty text node, and a empty text node was followed
by two nonempty text nodes.
I had expected commented statements, which failed.
The following test cases went with success instead.


public void testAdjacentTextNodes2() {
Element parent = new Element("parent");
Text empty = new Text("");
Text nonempty = new Text("value");
parent.appendChild(nonempty);
parent.appendChild(empty);
// Expected the following:
// Nodes result = parent.query("node()");
// assertEquals(2, result.size());
try {
Nodes result = parent.query("node()");
fail();
} catch (XPathException notExpected) {
assertTrue(true);
}
// Expected the following:
// Nodes result2 = parent.query("/*[count(node())=1]");
Nodes result2 = parent.query("/*[count(node())=2]");
assertEquals(1, result2.size());
assertEquals(parent, result2.get(0));

Nodes nodes1 = parent.query("node()[1]");
assertEquals(2, nodes1.size());
// Expected the following:
// Nodes nodes2 = parent.query("node()[2]");
// assertEquals(0, nodes2.size());
try {
Nodes nodes2 = parent.query("node()[2]");
fail();
} catch (XPathException notExpected) {
assertTrue(true);
}
}

public void testAdjacentTextNodes3() {
Element parent = new Element("parent");
Text empty = new Text("");
Text nonempty = new Text("value");
Text nonempty2 = new Text("value2");
parent.appendChild(empty);
parent.appendChild(nonempty);
parent.appendChild(nonempty2);
// Expected the following:
//Nodes result = parent.query("node()");
//assertEquals(3, result.size());
try {
Nodes result = parent.query("node()");
fail();
} catch (XPathException notExpected) {
assertTrue(true);
}
// Expected the following:
// Nodes result2 = parent.query("/*[count(node())=1]");
Nodes result2 = parent.query("/*[count(node())=2]");
assertEquals(1, result2.size());
assertEquals(parent, result2.get(0));

Nodes nodes1 = parent.query("node()[1]");
assertEquals(3, nodes1.size());
// Expected the following:
// Nodes nodes2 = parent.query("node()[2]");
// assertEquals(0, nodes2.size());
try {
Nodes nodes2 = parent.query("node()[2]");
fail();
} catch (XPathException notExpected) {
assertTrue(true);
}
}


I think that these may be bugs, or I am confused.
Could you give me any suggestion?
I use XOM 1.1 d3.

Thanks,
--
shirasu hiroyuki(hirsh AT s9.dion.ne.jp)




Archive powered by MHonArc 2.6.24.

Top of Page