public final void endElement(String uri, String localName, String qName) throws SAXException { try { endElementInternal(QNameUtils.toQName(uri, qName), namespaceContext); } catch (XMLStreamException ex) { throw new SAXException("Could not handle endElement: " + ex.getMessage(), ex); } }
public final void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { try { startElementInternal(QNameUtils.toQName(uri, qName), atts, namespaceContext); } catch (XMLStreamException ex) { throw new SAXException("Could not handle startElement: " + ex.getMessage(), ex); } }
private List<Attribute> getAttributes(Attributes attributes) { List<Attribute> list = new ArrayList<Attribute>(); for (int i = 0; i < attributes.getLength(); i++) { QName name = QNameUtils.toQName(attributes.getURI(i), attributes.getQName(i)); if (!("xmlns".equals(name.getLocalPart()) || "xmlns".equals(QNameUtils.getPrefix(name)))) { list.add(eventFactory.createAttribute(name, attributes.getValue(i))); } } return list; }
@Override protected void startElementInternal(QName name, Attributes attributes, SimpleNamespaceContext namespaceContext) throws XMLStreamException { streamWriter.writeStartElement(QNameUtils.getPrefix(name), name.getLocalPart(), name.getNamespaceURI()); String defaultNamespaceUri = namespaceContext.getNamespaceURI(""); if (StringUtils.hasLength(defaultNamespaceUri)) { streamWriter.writeNamespace("", defaultNamespaceUri); streamWriter.setDefaultNamespace(defaultNamespaceUri); } for (Iterator<String> iterator = namespaceContext.getBoundPrefixes(); iterator.hasNext();) { String prefix = iterator.next(); streamWriter.writeNamespace(prefix, namespaceContext.getNamespaceURI(prefix)); streamWriter.setPrefix(prefix, namespaceContext.getNamespaceURI(prefix)); } for (int i = 0; i < attributes.getLength(); i++) { QName attrName = QNameUtils.toQName(attributes.getURI(i), attributes.getQName(i)); String attrPrefix = QNameUtils.getPrefix(attrName); if (!("xmlns".equals(attrName.getLocalPart()) || "xmlns".equals(attrPrefix))) { streamWriter.writeAttribute(attrPrefix, attrName.getNamespaceURI(), attrName.getLocalPart(), attributes.getValue(i)); } } } }
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { OMContainer parent = getParent(); OMElement element = factory.createOMElement(localName, null, parent); for (Map.Entry<String, String> entry : namespaces.entrySet()) { String prefix = entry.getKey(); if (prefix.length() == 0) { element.declareDefaultNamespace((String) entry.getValue()); } else { element.declareNamespace((String) entry.getValue(), prefix); } } QName qname = QNameUtils.toQName(uri, qName); element.setLocalName(qname.getLocalPart()); element.setNamespace(element.findNamespace(qname.getNamespaceURI(), qname.getPrefix())); for (int i = 0; i < atts.getLength(); i++) { QName attrName = QNameUtils.toQName(atts.getURI(i), atts.getQName(i)); String value = atts.getValue(i); if (!atts.getQName(i).startsWith("xmlns")) { OMNamespace namespace = factory.createOMNamespace(attrName.getNamespaceURI(), attrName.getPrefix()); OMAttribute attribute = factory.createOMAttribute(attrName.getLocalPart(), namespace, value); element.addAttribute(attribute); } } elements.add(element); }