use of net.sf.saxon.tree.iter.AxisIterator in project sirix by sirixdb.
the class NodeWrapper method getAttributeValue.
@Override
public String getAttributeValue(final int fingerprint) {
String attVal = null;
final NameTest test = new NameTest(Type.ATTRIBUTE, fingerprint, getNamePool());
final AxisIterator iterator = iterateAxis(Axis.ATTRIBUTE, test);
final NodeInfo attribute = (NodeInfo) iterator.next();
if (attribute != null) {
attVal = attribute.getStringValue();
}
return attVal;
}
use of net.sf.saxon.tree.iter.AxisIterator in project sirix by sirixdb.
the class TestNodeWrapper method testGetBaseURI.
@Test
public void testGetBaseURI() throws Exception {
// Test with xml:base specified.
final File source = new File("src" + File.separator + "test" + File.separator + "resources" + File.separator + "data" + File.separator + "testBaseURI.xml");
final Session session = generateSession();
final NodeWriteTrx wtx = session.beginNodeWriteTrx();
final XMLEventReader reader = XMLShredder.createFileReader(source);
final XMLShredder shredder = new XMLShredder.Builder(wtx, reader, Insert.ASFIRSTCHILD).commitAfterwards().build();
shredder.call();
wtx.close();
final Processor proc = new Processor(false);
final NodeInfo doc = new DocumentWrapper(session, proc.getUnderlyingConfiguration());
doc.getNamePool().allocate("xml", "http://www.w3.org/XML/1998/namespace", "base");
doc.getNamePool().allocate("", "", "baz");
final NameTest test = new NameTest(Type.ELEMENT, "", "baz", doc.getNamePool());
final AxisIterator iterator = doc.iterateAxis(Axis.DESCENDANT, test);
final NodeInfo baz = (NodeInfo) iterator.next();
assertEquals("http://example.org", baz.getBaseURI());
session.close();
mDatabase.close();
}
use of net.sf.saxon.tree.iter.AxisIterator in project sirix by sirixdb.
the class TestNodeWrapper method testGetDeclaredNamespaces.
@Test
public void testGetDeclaredNamespaces() {
// Namespace declared.
final AxisIterator iterator = node.iterateAxis(Axis.CHILD);
node = (NodeWrapper) iterator.next();
final int[] namespaces = node.getDeclaredNamespaces(new int[1]);
node.getNamePool().allocateNamespaceCode("p", "ns");
final int expected = node.getNamePool().getNamespaceCode("p", "ns");
assertEquals(expected, namespaces[0]);
// Namespace not declared (on element node) -- returns zero length
// array.
final AxisIterator iter = node.iterateAxis(Axis.DESCENDANT);
node = (NodeWrapper) iter.next();
node = (NodeWrapper) iter.next();
final int[] namesp = node.getDeclaredNamespaces(new int[1]);
assertTrue(namesp.length == 0);
// Namespace nod declared on other nodes -- return null.
final AxisIterator it = node.iterateAxis(Axis.DESCENDANT);
node = (NodeWrapper) it.next();
assertNull(node.getDeclaredNamespaces(new int[1]));
}
use of net.sf.saxon.tree.iter.AxisIterator in project sirix by sirixdb.
the class TestNodeWrapper method testGetSiblingPosition.
@Test
public void testGetSiblingPosition() {
// Test every node in test document.
final AxisIterator iterator = node.iterateAxis(Axis.DESCENDANT);
node = (NodeWrapper) iterator.next();
node = (NodeWrapper) iterator.next();
assertEquals(0, node.getSiblingPosition());
node = (NodeWrapper) iterator.next();
assertEquals(1, node.getSiblingPosition());
node = (NodeWrapper) iterator.next();
assertEquals(0, node.getSiblingPosition());
node = (NodeWrapper) iterator.next();
assertEquals(1, node.getSiblingPosition());
node = (NodeWrapper) iterator.next();
assertEquals(2, node.getSiblingPosition());
node = (NodeWrapper) iterator.next();
assertEquals(3, node.getSiblingPosition());
node = (NodeWrapper) iterator.next();
assertEquals(0, node.getSiblingPosition());
node = (NodeWrapper) iterator.next();
assertEquals(1, node.getSiblingPosition());
node = (NodeWrapper) iterator.next();
assertEquals(4, node.getSiblingPosition());
}
use of net.sf.saxon.tree.iter.AxisIterator in project sirix by sirixdb.
the class TestNodeWrapper method testGetStringValueCS.
@Test
public void testGetStringValueCS() {
// Test on document node.
assertEquals("oops1foooops2baroops3", node.getStringValueCS());
// Test on element node.
AxisIterator iterator = node.iterateAxis(Axis.DESCENDANT);
node = (NodeWrapper) iterator.next();
assertEquals("oops1foooops2baroops3", node.getStringValueCS());
// Test on namespace node.
iterator = node.iterateAxis(Axis.NAMESPACE);
NamespaceNodeImpl namespace = (NamespaceNodeImpl) iterator.next();
/*
* Elements have always the default xml:NamespaceConstant.XML namespace, so
* we have to search if "ns" is found somewhere in the iterator (order
* unpredictable because it's implemented with a HashMap internally).
*/
while (!"ns".equals(namespace.getStringValueCS()) && namespace != null) {
namespace = (NamespaceNodeImpl) iterator.next();
}
if (namespace == null) {
fail("namespace is null!");
} else {
assertEquals("ns", namespace.getStringValueCS());
}
// Test on attribute node.
final NodeWrapper attrib = (NodeWrapper) node.iterateAxis(Axis.ATTRIBUTE).next();
assertEquals("j", attrib.getStringValueCS());
// Test on text node.
final NodeWrapper text = (NodeWrapper) node.iterateAxis(Axis.CHILD).next();
assertEquals("oops1", text.getStringValueCS());
}
Aggregations