StartElement se = evt.asStartElement();
testEventWritability(se);
// Let's first check that it has 1 declaration:
assertEquals(0, countElements(se.getNamespaces()));
NamespaceContext nsCtxt = se.getNamespaceContext();
assertNotNull("StartElement.getNamespaceContext() should never return null", nsCtxt);
assertNull(nsCtxt.getPrefix("a"));
assertNull(nsCtxt.getNamespaceURI("b"));
// then first leaf:
evt = er.nextEvent();
assertTrue(evt.isStartElement());
se = evt.asStartElement();
assertEquals("leaf", se.getName().getLocalPart());
assertEquals(1, countElements(se.getNamespaces()));
assertEquals("x", se.getName().getNamespaceURI());
nsCtxt = se.getNamespaceContext();
assertEquals("x", nsCtxt.getNamespaceURI(""));
assertEquals("", nsCtxt.getPrefix("x"));
testEventWritability(se);
evt = er.nextEvent();
assertTrue(evt.isEndElement());
testEventWritability(evt);
// Ok, branch:
evt = er.nextEvent();
assertTrue(evt.isStartElement());
se = evt.asStartElement();
assertEquals("branch", se.getName().getLocalPart());
assertEquals(2, countElements(se.getNamespaces()));
nsCtxt = se.getNamespaceContext();
assertEquals("a", nsCtxt.getPrefix("b"));
assertEquals("b", nsCtxt.getNamespaceURI("a"));
assertEquals("x", nsCtxt.getPrefix("url"));
assertEquals("url", nsCtxt.getNamespaceURI("x"));
testEventWritability(se);
// second leaf
evt = er.nextEvent();
assertTrue(evt.isStartElement());
se = evt.asStartElement();
nsCtxt = se.getNamespaceContext();
assertEquals("leaf", se.getName().getLocalPart());
// only one declared in this particular element
assertEquals(1, countElements(se.getNamespaces()));
// but should still show the other bound ns from parent
nsCtxt = se.getNamespaceContext();
assertEquals("a", nsCtxt.getPrefix("c"));
assertEquals("c", nsCtxt.getNamespaceURI("a"));
assertEquals("x", nsCtxt.getPrefix("url"));
assertEquals("url", nsCtxt.getNamespaceURI("x"));
// ok, but how about masking:
assertNull(nsCtxt.getPrefix("b"));
// Ok, fine... others we don't care about:
assertTrue(er.nextEvent().isEndElement());
}