Search in sources :

Example 1 with AttrNSImpl

use of org.apache.xerces.dom.AttrNSImpl in project exist by eXist-db.

the class DocumentImplTest method checkNamespaces_xerces.

@Test
public void checkNamespaces_xerces() throws IOException, ParserConfigurationException, SAXException {
    final Document doc;
    try (final InputStream is = new UnsynchronizedByteArrayInputStream(DOC_WITH_NAMESPACES.getBytes(UTF_8))) {
        doc = parseXerces(is);
    }
    final Element elem = doc.getDocumentElement();
    final NamedNodeMap attrs = elem.getAttributes();
    assertEquals(2, attrs.getLength());
    int index = 0;
    final Attr attr1 = (Attr) attrs.item(index++);
    assertEquals(Node.ATTRIBUTE_NODE, attr1.getNodeType());
    assertTrue(attr1 instanceof AttrNSImpl);
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, attr1.getNamespaceURI());
    assertEquals(null, attr1.getPrefix());
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE, attr1.getLocalName());
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE, attr1.getNodeName());
    assertEquals("http://exist-db.org/xquery/repo", attr1.getValue());
    final Attr attr2 = (Attr) attrs.item(index++);
    assertEquals(Node.ATTRIBUTE_NODE, attr2.getNodeType());
    assertTrue(attr2 instanceof AttrNSImpl);
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, attr2.getNamespaceURI());
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE, attr2.getPrefix());
    assertEquals("repo", attr2.getLocalName());
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE + ":repo", attr2.getNodeName());
    assertEquals("http://exist-db.org/xquery/repo", attr2.getValue());
}
Also used : AttrNSImpl(org.apache.xerces.dom.AttrNSImpl) UnsynchronizedByteArrayInputStream(org.apache.commons.io.input.UnsynchronizedByteArrayInputStream) InputStream(java.io.InputStream) UnsynchronizedByteArrayInputStream(org.apache.commons.io.input.UnsynchronizedByteArrayInputStream) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)1 UnsynchronizedByteArrayInputStream (org.apache.commons.io.input.UnsynchronizedByteArrayInputStream)1 AttrNSImpl (org.apache.xerces.dom.AttrNSImpl)1 Test (org.junit.Test)1