use of javax.xml.stream.events.Comment in project wso2-synapse by wso2.
the class DOMEventConsumer method add.
@Override
public void add(XMLEvent event) throws XMLStreamException {
switch(event.getEventType()) {
case XMLStreamConstants.CDATA:
node.appendChild(document.createCDATASection(event.asCharacters().getData()));
break;
case XMLStreamConstants.CHARACTERS:
node.appendChild(document.createTextNode(event.asCharacters().getData()));
break;
case XMLStreamConstants.COMMENT:
node.appendChild(document.createComment(((Comment) event).getText()));
break;
case XMLStreamConstants.END_ELEMENT:
node = node.getParentNode();
break;
case XMLStreamConstants.ENTITY_REFERENCE:
node.appendChild(document.createEntityReference(((EntityReference) event).getName()));
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
ProcessingInstruction pi = (ProcessingInstruction) event;
node.appendChild(document.createProcessingInstruction(pi.getTarget(), pi.getData()));
break;
case XMLStreamConstants.START_ELEMENT:
StartElement startElement = event.asStartElement();
QName elementName = startElement.getName();
Element element;
if (namespaceAware) {
element = document.createElementNS(elementName.getNamespaceURI(), qName(elementName));
} else {
element = document.createElement(elementName.getLocalPart());
}
Iterator<?> namespaces = startElement.getNamespaces();
while (namespaces.hasNext()) {
Namespace ns = (Namespace) namespaces.next();
element.setAttributeNS(ns.getName().getNamespaceURI(), qName(ns.getName()), ns.getNamespaceURI());
}
Iterator<?> attributes = startElement.getAttributes();
while (attributes.hasNext()) {
Attribute at = (Attribute) attributes.next();
if (namespaceAware) {
element.setAttributeNS(at.getName().getNamespaceURI(), qName(at.getName()), at.getValue());
} else {
element.setAttribute(at.getName().getLocalPart(), at.getValue());
}
}
node = node.appendChild(element);
break;
case XMLStreamConstants.SPACE:
case XMLStreamConstants.ENTITY_DECLARATION:
case XMLStreamConstants.NOTATION_DECLARATION:
case XMLStreamConstants.START_DOCUMENT:
case XMLStreamConstants.END_DOCUMENT:
case XMLStreamConstants.DTD:
break;
default:
throw new XMLStreamException("Unexpected event type " + event.getEventType() + "; " + event);
}
}
use of javax.xml.stream.events.Comment in project wso2-synapse by wso2.
the class SimpleXMLEventAllocatorTest method testComment.
@Test
public void testComment() throws XMLStreamException {
XMLStreamReader reader = createXmlStreamReader("<!-- james -->");
Comment comment = (Comment) eventAllocator.allocate(reader);
verify(comment, XMLStreamConstants.COMMENT, "<!-- james -->");
Assert.assertEquals(" james ", comment.getText());
}
use of javax.xml.stream.events.Comment in project wso2-synapse by wso2.
the class SimpleXMLEventFactoryTest method testCreateComment.
@Test
public void testCreateComment() throws XMLStreamException {
Comment event = factory.createComment("foo");
verify(event, XMLStreamConstants.COMMENT, "<!--foo-->");
}
Aggregations