@Test public void testAttributeNamespace() throws XMLStreamException { XMLStreamReader reader = createXmlStreamReader("<alice david=\"edgar\" xmlns=\"http: StartElement startElement = eventAllocator.allocate(reader).asStartElement(); verify(startElement, XMLStreamConstants.START_ELEMENT, "<alice xmlns=\"http: Iterator<?> attributes = startElement.getAttributes(); Assert.assertTrue(attributes.hasNext()); Attribute attribute = (Attribute)attributes.next(); verify(attribute, XMLStreamConstants.ATTRIBUTE, "david=\"edgar\""); Assert.assertEquals(new QName("david"), attribute.getName()); Assert.assertEquals("edgar", attribute.getValue()); Assert.assertFalse(attributes.hasNext()); Iterator<?> namespaces = startElement.getNamespaces(); Assert.assertTrue(namespaces.hasNext()); Namespace namespace = (Namespace)namespaces.next(); verify(namespace, XMLStreamConstants.NAMESPACE, "xmlns=\"http: Assert.assertEquals(new QName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns"), namespace.getName()); Assert.assertEquals("http: Assert.assertEquals(XMLConstants.DEFAULT_NS_PREFIX, namespace.getPrefix()); Assert.assertEquals("http: Assert.assertFalse(namespaces.hasNext()); reader = createXmlStreamReader("<alice p:david=\"edgar\" xmlns:p=\"http: startElement = eventAllocator.allocate(reader).asStartElement(); verify(startElement, XMLStreamConstants.START_ELEMENT, "<alice xmlns:p=\"http: attributes = startElement.getAttributes(); Assert.assertTrue(attributes.hasNext()); attribute = (Attribute)attributes.next(); verify(attribute, XMLStreamConstants.ATTRIBUTE, "p:david=\"edgar\""); Assert.assertEquals(new QName("http: Assert.assertEquals("edgar", attribute.getValue()); Assert.assertFalse(attributes.hasNext()); namespaces = startElement.getNamespaces(); Assert.assertTrue(namespaces.hasNext()); namespace = (Namespace)namespaces.next(); verify(namespace, XMLStreamConstants.NAMESPACE, "xmlns:p=\"http: Assert.assertEquals(new QName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "p", "xmlns"), namespace.getName()); Assert.assertEquals("http: Assert.assertEquals("p", namespace.getPrefix()); Assert.assertEquals("http: Assert.assertFalse(namespaces.hasNext()); }
@Override public XMLEvent allocate(XMLStreamReader reader) throws XMLStreamException { switch (reader.getEventType()) { case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: return new CharactersEvent(reader); case XMLStreamConstants.COMMENT: return new CommentEvent(reader); case XMLStreamConstants.DTD: throw new UnsupportedOperationException(); case XMLStreamConstants.END_DOCUMENT: return new EndDocumentEvent(reader); case XMLStreamConstants.END_ELEMENT: return new EndElementEvent(reader); case XMLStreamConstants.ENTITY_REFERENCE: return new EntityReferenceEvent(reader); case XMLStreamConstants.NOTATION_DECLARATION: throw new UnsupportedOperationException(); case XMLStreamConstants.PROCESSING_INSTRUCTION: return new ProcessingInstructionEvent(reader); case XMLStreamConstants.START_DOCUMENT: return new StartDocumentEvent(reader); case XMLStreamConstants.START_ELEMENT: return new StartElementEvent(reader); default: throw new XMLStreamException("Unexpected event type: " + reader.getEventType()); } }
SimpleXMLEventAllocator implements XMLEventAllocator { @Override public XMLEvent allocate(XMLStreamReader reader) throws XMLStreamException { switch (reader.getEventType()) { case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: return new CharactersEvent(reader); case XMLStreamConstants.COMMENT: return new CommentEvent(reader); case XMLStreamConstants.DTD: throw new UnsupportedOperationException(); case XMLStreamConstants.END_DOCUMENT: return new EndDocumentEvent(reader); case XMLStreamConstants.END_ELEMENT: return new EndElementEvent(reader); case XMLStreamConstants.ENTITY_REFERENCE: return new EntityReferenceEvent(reader); case XMLStreamConstants.NOTATION_DECLARATION: throw new UnsupportedOperationException(); case XMLStreamConstants.PROCESSING_INSTRUCTION: return new ProcessingInstructionEvent(reader); case XMLStreamConstants.START_DOCUMENT: return new StartDocumentEvent(reader); case XMLStreamConstants.START_ELEMENT: return new StartElementEvent(reader); default: throw new XMLStreamException("Unexpected event type: " + reader.getEventType()); } } }
SimpleXMLEventAllocator implements XMLEventAllocator { @Override public XMLEvent allocate(XMLStreamReader reader) throws XMLStreamException { switch (reader.getEventType()) { case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: return new CharactersEvent(reader); case XMLStreamConstants.COMMENT: return new CommentEvent(reader); case XMLStreamConstants.DTD: throw new UnsupportedOperationException(); case XMLStreamConstants.END_DOCUMENT: return new EndDocumentEvent(reader); case XMLStreamConstants.END_ELEMENT: return new EndElementEvent(reader); case XMLStreamConstants.ENTITY_REFERENCE: return new EntityReferenceEvent(reader); case XMLStreamConstants.NOTATION_DECLARATION: throw new UnsupportedOperationException(); case XMLStreamConstants.PROCESSING_INSTRUCTION: return new ProcessingInstructionEvent(reader); case XMLStreamConstants.START_DOCUMENT: return new StartDocumentEvent(reader); case XMLStreamConstants.START_ELEMENT: return new StartElementEvent(reader); default: throw new XMLStreamException("Unexpected event type: " + reader.getEventType()); } }  }
SimpleXMLEventAllocator implements XMLEventAllocator { @Override public XMLEvent allocate(XMLStreamReader reader) throws XMLStreamException { switch (reader.getEventType()) { case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: return new CharactersEvent(reader); case XMLStreamConstants.COMMENT: return new CommentEvent(reader); case XMLStreamConstants.DTD: throw new UnsupportedOperationException(); case XMLStreamConstants.END_DOCUMENT: return new EndDocumentEvent(reader); case XMLStreamConstants.END_ELEMENT: return new EndElementEvent(reader); case XMLStreamConstants.ENTITY_REFERENCE: return new EntityReferenceEvent(reader); case XMLStreamConstants.NOTATION_DECLARATION: throw new UnsupportedOperationException(); case XMLStreamConstants.PROCESSING_INSTRUCTION: return new ProcessingInstructionEvent(reader); case XMLStreamConstants.START_DOCUMENT: return new StartDocumentEvent(reader); case XMLStreamConstants.START_ELEMENT: return new StartElementEvent(reader); default: throw new XMLStreamException("Unexpected event type: " + reader.getEventType()); } }  @Override XMLEventAllocator newInstance(); @Override XMLEvent allocate(XMLStreamReader reader); @Override void allocate(XMLStreamReader reader, XMLEventConsumer consumer); }
SimpleXMLEventAllocator implements XMLEventAllocator { @Override public XMLEvent allocate(XMLStreamReader reader) throws XMLStreamException { switch (reader.getEventType()) { case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: return new CharactersEvent(reader); case XMLStreamConstants.COMMENT: return new CommentEvent(reader); case XMLStreamConstants.DTD: throw new UnsupportedOperationException(); case XMLStreamConstants.END_DOCUMENT: return new EndDocumentEvent(reader); case XMLStreamConstants.END_ELEMENT: return new EndElementEvent(reader); case XMLStreamConstants.ENTITY_REFERENCE: return new EntityReferenceEvent(reader); case XMLStreamConstants.NOTATION_DECLARATION: throw new UnsupportedOperationException(); case XMLStreamConstants.PROCESSING_INSTRUCTION: return new ProcessingInstructionEvent(reader); case XMLStreamConstants.START_DOCUMENT: return new StartDocumentEvent(reader); case XMLStreamConstants.START_ELEMENT: return new StartElementEvent(reader); default: throw new XMLStreamException("Unexpected event type: " + reader.getEventType()); } }  @Override XMLEventAllocator newInstance(); @Override XMLEvent allocate(XMLStreamReader reader); @Override void allocate(XMLStreamReader reader, XMLEventConsumer consumer);  }