Search in sources :

Example 1 with AxisIterator

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;
}
Also used : NameTest(net.sf.saxon.pattern.NameTest) NodeInfo(net.sf.saxon.om.NodeInfo) AxisIterator(net.sf.saxon.tree.iter.AxisIterator)

Example 2 with AxisIterator

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();
}
Also used : NameTest(net.sf.saxon.pattern.NameTest) Processor(net.sf.saxon.s9api.Processor) NodeInfo(net.sf.saxon.om.NodeInfo) NodeWriteTrx(org.sirix.api.NodeWriteTrx) XMLEventReader(javax.xml.stream.XMLEventReader) XMLShredder(org.sirix.service.xml.shredder.XMLShredder) File(java.io.File) AxisIterator(net.sf.saxon.tree.iter.AxisIterator) Session(org.sirix.api.Session) NameTest(net.sf.saxon.pattern.NameTest) Test(org.junit.Test)

Example 3 with AxisIterator

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]));
}
Also used : AxisIterator(net.sf.saxon.tree.iter.AxisIterator) NameTest(net.sf.saxon.pattern.NameTest) Test(org.junit.Test)

Example 4 with AxisIterator

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());
}
Also used : AxisIterator(net.sf.saxon.tree.iter.AxisIterator) NameTest(net.sf.saxon.pattern.NameTest) Test(org.junit.Test)

Example 5 with AxisIterator

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());
}
Also used : NamespaceNodeImpl(net.sf.saxon.tree.iter.NamespaceIterator.NamespaceNodeImpl) AxisIterator(net.sf.saxon.tree.iter.AxisIterator) NameTest(net.sf.saxon.pattern.NameTest) Test(org.junit.Test)

Aggregations

NameTest (net.sf.saxon.pattern.NameTest)6 AxisIterator (net.sf.saxon.tree.iter.AxisIterator)6 Test (org.junit.Test)5 NodeInfo (net.sf.saxon.om.NodeInfo)3 Processor (net.sf.saxon.s9api.Processor)2 File (java.io.File)1 XMLEventReader (javax.xml.stream.XMLEventReader)1 NamespaceNodeImpl (net.sf.saxon.tree.iter.NamespaceIterator.NamespaceNodeImpl)1 NodeWriteTrx (org.sirix.api.NodeWriteTrx)1 Session (org.sirix.api.Session)1 XMLShredder (org.sirix.service.xml.shredder.XMLShredder)1