List of usage examples for javax.xml.stream XMLEventWriter setDefaultNamespace
public void setDefaultNamespace(String uri) throws XMLStreamException;
From source file:org.springframework.batch.item.xml.StaxEventItemWriter.java
/** * Inits the namespace context of the XMLEventWriter: * <ul>/*from w w w. jav a 2s .c o m*/ * <li>rootTagNamespacePrefix for rootTagName</li> * <li>any other xmlns namespace prefix declarations in the root element attributes</li> * </ul> * * @param writer XML event writer * @throws XMLStreamException */ protected void initNamespaceContext(XMLEventWriter writer) throws XMLStreamException { if (StringUtils.hasText(getRootTagNamespace())) { if (StringUtils.hasText(getRootTagNamespacePrefix())) { writer.setPrefix(getRootTagNamespacePrefix(), getRootTagNamespace()); } else { writer.setDefaultNamespace(getRootTagNamespace()); } } if (!CollectionUtils.isEmpty(getRootElementAttributes())) { for (Map.Entry<String, String> entry : getRootElementAttributes().entrySet()) { String key = entry.getKey(); if (key.startsWith("xmlns")) { String prefix = ""; if (key.contains(":")) { prefix = key.substring(key.indexOf(":") + 1); } if (log.isDebugEnabled()) { log.debug("registering prefix: " + prefix + "=" + entry.getValue()); } writer.setPrefix(prefix, entry.getValue()); } } } }