List of usage examples for javax.xml.stream XMLStreamWriter writeAttribute
public void writeAttribute(String localName, String value) throws XMLStreamException;
From source file:de.codesourcery.eve.skills.dao.impl.FileShoppingListDAO.java
protected void writeToFile() { XMLStreamWriter writer = null; try {//from w w w . jav a 2s . c o m if (!dataFile.exists()) { final File parent = dataFile.getParentFile(); if (parent != null && !parent.exists()) { if (!parent.mkdirs()) { log.error("writeToFile(): Failed to create parent directory " + parent.getAbsolutePath()); } else { log.info("writeToFile(): Created parent directory " + parent.getAbsolutePath()); } } } final XMLOutputFactory factory = XMLOutputFactory.newInstance(); log.info("writeToFile(): Writing to " + dataFile.getAbsolutePath()); final FileOutputStream outStream = new FileOutputStream(dataFile); writer = factory.createXMLStreamWriter(outStream, OUTPUT_ENCODING); writer.writeStartDocument(OUTPUT_ENCODING, "1.0"); writer.writeStartElement("shoppinglists"); // <shoppinglists> synchronized (this.entries) { for (ShoppingList list : this.entries) { writer.writeStartElement("shoppinglist"); writer.writeAttribute("title", list.getTitle()); if (!StringUtils.isBlank(list.getDescription())) { writer.writeStartElement("description"); writer.writeCharacters(list.getDescription()); writer.writeEndElement(); // </description> } writer.writeStartElement("entries"); for (ShoppingListEntry entry : list.getEntries()) { writer.writeStartElement("entry"); writer.writeAttribute("itemId", Long.toString(entry.getType().getId())); writer.writeAttribute("totalQuantity", Long.toString(entry.getQuantity())); writer.writeAttribute("purchasedQuantity", Long.toString(entry.getPurchasedQuantity())); writer.writeEndElement(); // </entry> } writer.writeEndElement(); // </entries> writer.writeEndElement(); // </shoppinglist> } } writer.writeEndElement(); // </shoppinglists> writer.writeEndDocument(); writer.flush(); writer.close(); } catch (FileNotFoundException e) { log.error("writeToFile(): Caught ", e); throw new RuntimeException("Unable to save shopping list to " + dataFile, e); } catch (XMLStreamException e) { log.error("writeToFile(): Caught ", e); throw new RuntimeException("Unable to save shopping list to " + dataFile, e); } finally { if (writer != null) { try { writer.close(); } catch (XMLStreamException e) { log.error("writeToFile(): Caught ", e); } } } }
From source file:de.codesourcery.eve.skills.util.XMLMapper.java
public void write(Collection<?> beans, IFieldConverters converters, OutputStream outstream) throws XMLStreamException, IntrospectionException, IllegalArgumentException, IllegalAccessException { final XMLOutputFactory factory = XMLOutputFactory.newInstance(); final XMLStreamWriter writer = factory.createXMLStreamWriter(outstream, OUTPUT_ENCODING); try {/*from w w w . j a v a2 s. c om*/ writer.writeStartDocument(OUTPUT_ENCODING, "1.0"); writer.writeStartElement("rows"); if (beans.isEmpty()) { writer.writeEndDocument(); return; } final Class<?> beanClass = beans.iterator().next().getClass(); final BeanDescription desc = createBeanDescription(beanClass); final Collection<Field> fields = desc.getFields(); if (fields.isEmpty()) { writer.writeEndDocument(); return; } for (Object bean : beans) { writer.writeStartElement("row"); for (Field f : fields) { final Object fieldValue = f.get(bean); final String[] values = converters.getConverter(f).toString(fieldValue); final String attrName = this.propertyNameMappings.get(f.getName()); if (values == null) { writer.writeAttribute(f.getName(), NIL); } else if (attrName == null) { writer.writeAttribute(f.getName(), toAttributeValue(values)); } else { writer.writeAttribute(attrName, toAttributeValue(values)); } } writer.writeEndElement(); } writer.writeEndDocument(); } finally { writer.close(); } }
From source file:ca.uhn.fhir.parser.XmlParser.java
@Override public void encodeTagListToWriter(TagList theTagList, Writer theWriter) throws IOException { try {/*from ww w. java2s .co m*/ XMLStreamWriter eventWriter = createXmlWriter(theWriter); eventWriter.writeStartElement(TagList.ELEMENT_NAME_LC); eventWriter.writeDefaultNamespace(FHIR_NS); for (Tag next : theTagList) { eventWriter.writeStartElement(TagList.ATTR_CATEGORY); if (isNotBlank(next.getTerm())) { eventWriter.writeAttribute(Tag.ATTR_TERM, next.getTerm()); } if (isNotBlank(next.getLabel())) { eventWriter.writeAttribute(Tag.ATTR_LABEL, next.getLabel()); } if (isNotBlank(next.getScheme())) { eventWriter.writeAttribute(Tag.ATTR_SCHEME, next.getScheme()); } eventWriter.writeEndElement(); } eventWriter.writeEndElement(); eventWriter.close(); } catch (XMLStreamException e) { throw new ConfigurationException("Failed to initialize STaX event factory", e); } }
From source file:com.fiorano.openesb.application.application.PortInstance.java
protected void toJXMLString_1(XMLStreamWriter writer, boolean writeSchema) throws XMLStreamException, FioranoException { if (proxyUsed || !StringUtils.isEmpty(proxyURL) || !ANONYMOUS.equals(proxyUser) || !ANONYMOUS.equals(proxyPassword)) { writer.writeStartElement(ELEM_PROXY); {/*w w w . j a v a 2s .c om*/ if (proxyUsed) writer.writeAttribute(ATTR_PROXY_USED, String.valueOf(proxyUsed)); writeAttribute(writer, ATTR_PROXY_URL, proxyURL); if (!ANONYMOUS.equals(proxyUser) || !ANONYMOUS.equals(proxyPassword)) { writer.writeStartElement(ELEM_AUTHENTICATION); { if (!ANONYMOUS.equals(proxyUser)) writer.writeAttribute(ATTR_PROXY_USER, proxyUser); if (!ANONYMOUS.equals(proxyPassword)) writer.writeAttribute(ATTR_PROXY_PASSWORD, proxyPassword); } writer.writeEndElement(); } } writer.writeEndElement(); } writer.writeStartElement(ELEM_JMS); { writeAttribute(writer, ATTR_CLIENT_ID, clientID); if (!enabled) writer.writeAttribute(ATTR_ENABLED, String.valueOf(enabled)); if (writeSchema || destinationConfigName == null) { writer.writeStartElement(ELEM_DESTINATION); { if (destinationType != getDefaultDestinationType()) writer.writeAttribute(ATTR_DESTINATION_TYPE, String.valueOf(destinationType)); if (specifiedDestinationUsed) writer.writeAttribute(ATTR_SPECIFIED_DESTINATION_USED, String.valueOf(specifiedDestinationUsed)); writeAttribute(writer, ATTR_DESTINATION, destination); if (isDestinationEncrypted) { writer.writeAttribute(IS_DESTINATION_ENCRYPTED, String.valueOf(isDestinationEncrypted)); writer.writeAttribute(DESTINATION_ENCRYPT_ALGO, encryptionAlgorithm); if (encryptionKey == null || encryptionKey.equals("")) writer.writeAttribute(DESTINATION_ENCRYPT_KEY, ""); else writer.writeAttribute(DESTINATION_ENCRYPT_KEY, encryptionKey); writer.writeAttribute(DESTINATION_ALLOW_PADDING_TO_KEY, String.valueOf(allowPaddingToKey)); writer.writeAttribute(DESTINATION_INITIALIZATION_VECTOR, initializationVector); } } writer.writeEndElement(); } else if (destinationConfigName != null) { writer.writeStartElement(ELEM_DESTINATION_CONFIG_NAME); writer.writeAttribute(ATTR_NAME, destinationConfigName); writer.writeEndElement(); } if (!StringUtils.isEmpty(securityManager) || !ANONYMOUS.equals(user) || !ANONYMOUS.equals(password)) { writer.writeStartElement(ELEM_AUTHENTICATION); { writeAttribute(writer, ATTR_SECURITY_MANAGER, securityManager); if (!ANONYMOUS.equals(user)) writer.writeAttribute(ATTR_USER, user); if (!ANONYMOUS.equals(password)) writer.writeAttribute(ATTR_PASSWORD, password); } writer.writeEndElement(); } toJXMLString_2(writer, writeSchema); } writer.writeEndElement(); if ((writeSchema || workflowConfigName == null)) { // We need to write port properties to stream when passing application launch packet to peer writer.writeStartElement(ELEM_WORKFLOW); writer.writeAttribute(ATTR_WORKFLOW_TYPE, String.valueOf(workflow)); writer.writeAttribute(ATTR_WORKFLOW_DATATYPE, String.valueOf(workflowDataType)); writer.writeAttribute(ATTR_CALLOUT_ENABLED, String.valueOf(calloutEnabled)); for (DBCallOutParameter dbCallOutParameter : dbCallOutParameterList) { dbCallOutParameter.toJXMLString(writer); } writer.writeEndElement(); } else if (workflowConfigName != null) { writer.writeStartElement(ELEM_WORKFLOW_CONFIG_NAME); writer.writeAttribute(ATTR_NAME, workflowConfigName); writer.writeEndElement(); } if ((writeSchema || messageFilterConfigName == null) && (isMessageFilterSet)) { writer.writeStartElement(ELEM_MESSAGE_FILTERS); for (Iterator itr = messageFilters.entrySet().iterator(); itr.hasNext();) { Map.Entry entry = (Map.Entry) itr.next(); writer.writeStartElement(ELEM_MESSAGE_FILTER); writer.writeAttribute(ATTR_MESSAGE_FILTER_NAME, (String) entry.getKey()); writer.writeAttribute(ATTR_MESSAGE_FILTER_VALUE, (String) entry.getValue()); writer.writeEndElement(); } writer.writeEndElement(); } else if (messageFilterConfigName != null) { writer.writeStartElement(ELEM_MESSAGE_FILTER_CONFIG_NAME); writer.writeAttribute(ATTR_NAME, messageFilterConfigName); writer.writeEndElement(); } if (!appContextAction.equalsIgnoreCase(NO_ACTION_APP_CONTEXT)) { writer.writeStartElement(ELEM_APP_CONTEXT_ACTION); writer.writeCharacters(appContextAction); writer.writeEndElement(); } toJXMLString_3(writer, writeSchema); }
From source file:com.fiorano.openesb.application.aps.Route.java
public void toJXMLString(XMLStreamWriter writer) throws XMLStreamException { //Start Route writer.writeStartElement("Route"); //Add Route Attributes writer.writeAttribute("isP2PRoute", "" + m_isP2PRoute); writer.writeAttribute("isPersistant", "" + m_isPersitant); writer.writeAttribute("isDurable", "" + m_isDurable); writer.writeAttribute("applyTransformationAtSrc", "" + m_applyTransformationAtSrc); //Name/*from w ww.j av a 2 s . c om*/ FioranoStackSerializer.writeElement("Name", m_routeName, writer); //RouteGuid FioranoStackSerializer.writeElement("RouteGUID", m_routeGUID, writer); //TimeToLive FioranoStackSerializer.writeElement("TimeToLive", "" + m_iTimeToLive, writer); //SrcServiceInstance FioranoStackSerializer.writeElement("SrcServiceInstance", m_srcServInst, writer); //SrcPort FioranoStackSerializer.writeElement("SrcPort", m_srcPortName, writer); //TransformationXSL if (m_transformationXSL != null) { writer.writeStartElement("TransformationXSL"); writer.writeCData(m_transformationXSL); writer.writeEndElement(); } //Selectors if (m_selectors != null) { Iterator itr = m_selectors.keySet().iterator(); while (itr.hasNext()) { writer.writeStartElement("Selector"); String type = (String) itr.next(); writer.writeAttribute("type", type); Object val = m_selectors.get(type); String value = null; if (val instanceof String) { value = (String) m_selectors.get(type); } else if (val instanceof XPathDmi) { value = ((XPathDmi) val).getXPath(); HashMap map = ((XPathDmi) val).getNameSpace(); if (map != null) { Set keys = map.keySet(); Iterator iter = keys.iterator(); while (iter.hasNext()) { String key = (String) iter.next(); String keyval = (String) map.get(key); writer.writeAttribute("esb_" + key, keyval); } } } writer.writeCharacters(value); //End Selector writer.writeEndElement(); } } //TgtServiceInstance FioranoStackSerializer.writeElement("TgtServiceInstance", m_trgtServInst, writer); //TgtPort FioranoStackSerializer.writeElement("TgtPort", m_trgtPortName, writer); //LongDescription if (!StringUtils.isEmpty(m_longDescription)) { FioranoStackSerializer.writeElement("LongDescription", m_longDescription, writer); } //ShortDescription if (!StringUtils.isEmpty(m_shortDescription)) { FioranoStackSerializer.writeElement("ShortDescription", m_shortDescription, writer); } if (m_altDestination != null) { m_altDestination.toJXMLString(writer); } if (m_params != null && m_params.size() > 0) { Enumeration enums = m_params.elements(); while (enums.hasMoreElements()) { Param param = (Param) enums.nextElement(); if (!StringUtils.isEmpty(param.getParamName()) && !StringUtils.isEmpty(param.getParamValue())) param.toJXMLString(writer); } } //End Route writer.writeEndElement(); }
From source file:de.uni_koblenz.jgralab.utilities.rsa2tg.SchemaGraph2XMI.java
/** * This method creates an <code>extension</code> tag. It is used in profile * application and to create stereotypes of the form * <code><<keyValue>></code>. In the first case a * <code>references</code> child is created in the other a * <code>details</code> child. To create the first one <code>nelement</code> * has to be <code>null</code>. * //ww w . jav a2 s . c o m * @param writer * {@link XMLStreamWriter} of the current XMI file * @param nelement * {@link NamedElement} if null <code>references</code> is * created otherwise the stereotype <code>keyValue</code>. * @param keyValue * {@link String} the stereotype to be created * @throws XMLStreamException */ private void createExtension(XMLStreamWriter writer, NamedElement nelement, String keyValue) throws XMLStreamException { // start Extension writer.writeStartElement(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_TAG_EXTENSION); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_EXTENDER, XMIConstants4SchemaGraph2XMI.NAMESPACE_ECORE); // start eAnnotations writer.writeStartElement(XMIConstants4SchemaGraph2XMI.TAG_EANNOTATIONS); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.EANNOTATIONS_TYPE_VALUE); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, nelement != null ? nelement.get_qualifiedName() + "_" + XMIConstants4SchemaGraph2XMI.TAG_EANNOTATIONS : XMIConstants4SchemaGraph2XMI.TAG_EANNOTATIONS + System.currentTimeMillis()); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.EANNOTATIONS_ATTRIBUTE_SOURCE, XMIConstants4SchemaGraph2XMI.EANNOTATIONS_ATTRIBUTE_SOURCE_VALUE); if (nelement != null) { // write details writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_DETAILS); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.DETAILS_ATTRIBUTE_TYPE_VALUE); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_ID, nelement.get_qualifiedName() + "_" + XMIConstants4SchemaGraph2XMI.TAG_DETAILS); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.DETAILS_ATTRIBUTE_KEY, keyValue); } else { // write references writer.writeEmptyElement(XMIConstants4SchemaGraph2XMI.TAG_REFERENCES); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.NAMESPACE_XMI, XMIConstants4SchemaGraph2XMI.XMI_ATTRIBUTE_TYPE, XMIConstants4SchemaGraph2XMI.REFERENCES_TYPE_VALUE); writer.writeAttribute(XMIConstants4SchemaGraph2XMI.ATTRIBUTE_HREF, XMIConstants4SchemaGraph2XMI.REFERENCES_HREF_VALUE); } // close eAnnotations writer.writeEndElement(); // close Extension writer.writeEndElement(); }
From source file:ca.uhn.fhir.parser.XmlParser.java
private void encodeXhtml(XhtmlDt theDt, XMLStreamWriter theEventWriter) throws XMLStreamException { if (theDt == null || theDt.getValue() == null) { return;/*from w w w .jav a 2 s.co m*/ } boolean firstElement = true; for (XMLEvent event : theDt.getValue()) { switch (event.getEventType()) { case XMLStreamConstants.ATTRIBUTE: Attribute attr = (Attribute) event; if (isBlank(attr.getName().getPrefix())) { if (isBlank(attr.getName().getNamespaceURI())) { theEventWriter.writeAttribute(attr.getName().getLocalPart(), attr.getValue()); } else { theEventWriter.writeAttribute(attr.getName().getNamespaceURI(), attr.getName().getLocalPart(), attr.getValue()); } } else { theEventWriter.writeAttribute(attr.getName().getPrefix(), attr.getName().getNamespaceURI(), attr.getName().getLocalPart(), attr.getValue()); } break; case XMLStreamConstants.CDATA: theEventWriter.writeCData(((Characters) event).getData()); break; case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: String data = ((Characters) event).getData(); theEventWriter.writeCharacters(data); break; case XMLStreamConstants.COMMENT: theEventWriter.writeComment(((Comment) event).getText()); break; case XMLStreamConstants.END_ELEMENT: theEventWriter.writeEndElement(); break; case XMLStreamConstants.ENTITY_REFERENCE: EntityReference er = (EntityReference) event; theEventWriter.writeEntityRef(er.getName()); break; case XMLStreamConstants.NAMESPACE: Namespace ns = (Namespace) event; theEventWriter.writeNamespace(ns.getPrefix(), ns.getNamespaceURI()); break; case XMLStreamConstants.START_ELEMENT: StartElement se = event.asStartElement(); if (firstElement) { if (StringUtils.isBlank(se.getName().getPrefix())) { String namespaceURI = se.getName().getNamespaceURI(); if (StringUtils.isBlank(namespaceURI)) { namespaceURI = "http://www.w3.org/1999/xhtml"; } theEventWriter.writeStartElement(se.getName().getLocalPart()); theEventWriter.writeDefaultNamespace(namespaceURI); } else { String prefix = se.getName().getPrefix(); String namespaceURI = se.getName().getNamespaceURI(); theEventWriter.writeStartElement(prefix, se.getName().getLocalPart(), namespaceURI); theEventWriter.writeNamespace(prefix, namespaceURI); } firstElement = false; } else { if (isBlank(se.getName().getPrefix())) { if (isBlank(se.getName().getNamespaceURI())) { theEventWriter.writeStartElement(se.getName().getLocalPart()); } else { if (StringUtils.isBlank(se.getName().getPrefix())) { theEventWriter.writeStartElement(se.getName().getLocalPart()); // theEventWriter.writeDefaultNamespace(se.getName().getNamespaceURI()); } else { theEventWriter.writeStartElement(se.getName().getNamespaceURI(), se.getName().getLocalPart()); } } } else { theEventWriter.writeStartElement(se.getName().getPrefix(), se.getName().getLocalPart(), se.getName().getNamespaceURI()); } for (Iterator<?> attrIter = se.getAttributes(); attrIter.hasNext();) { Attribute next = (Attribute) attrIter.next(); theEventWriter.writeAttribute(next.getName().getLocalPart(), next.getValue()); } } break; case XMLStreamConstants.DTD: case XMLStreamConstants.END_DOCUMENT: case XMLStreamConstants.ENTITY_DECLARATION: case XMLStreamConstants.NOTATION_DECLARATION: case XMLStreamConstants.PROCESSING_INSTRUCTION: case XMLStreamConstants.START_DOCUMENT: break; } } }
From source file:ca.uhn.fhir.parser.XmlParser.java
private void encodeUndeclaredExtensions(IBaseResource theResource, XMLStreamWriter theEventWriter, List<? extends IBaseExtension<?, ?>> theExtensions, String tagName, boolean theIncludedResource) throws XMLStreamException, DataFormatException { for (IBaseExtension<?, ?> next : theExtensions) { if (next == null || (ElementUtil.isEmpty(next.getValue()) && next.getExtension().isEmpty())) { continue; }/*from w ww. j a v a2 s .co m*/ writeCommentsPre(theEventWriter, next); theEventWriter.writeStartElement(tagName); String elementId = getCompositeElementId(next); if (isNotBlank(elementId)) { theEventWriter.writeAttribute("id", elementId); } String url = next.getUrl(); theEventWriter.writeAttribute("url", url); if (next.getValue() != null) { IBaseDatatype value = next.getValue(); RuntimeChildUndeclaredExtensionDefinition extDef = myContext .getRuntimeChildUndeclaredExtensionDefinition(); String childName = extDef.getChildNameByDatatype(value.getClass()); BaseRuntimeElementDefinition<?> childDef; if (childName == null) { childDef = myContext.getElementDefinition(value.getClass()); if (childDef == null) { throw new ConfigurationException( "Unable to encode extension, unrecognized child element type: " + value.getClass().getCanonicalName()); } else { childName = RuntimeChildUndeclaredExtensionDefinition.createExtensionChildName(childDef); } } else { childDef = extDef.getChildElementDefinitionByDatatype(value.getClass()); if (childDef == null) { throw new ConfigurationException( "Unable to encode extension, unrecognized child element type: " + value.getClass().getCanonicalName()); } } encodeChildElementToStreamWriter(theResource, theEventWriter, value, childName, childDef, null, theIncludedResource, null); } // child extensions encodeExtensionsIfPresent(theResource, theEventWriter, next, theIncludedResource); theEventWriter.writeEndElement(); writeCommentsPost(theEventWriter, next); } }
From source file:ca.uhn.fhir.parser.XmlParser.java
private void encodeExtension(IBaseResource theResource, XMLStreamWriter theEventWriter, boolean theContainedResource, CompositeChildElement nextChildElem, BaseRuntimeChildDefinition nextChild, IBase nextValue, String childName, String extensionUrl, BaseRuntimeElementDefinition<?> childDef) throws XMLStreamException { BaseRuntimeDeclaredChildDefinition extDef = (BaseRuntimeDeclaredChildDefinition) nextChild; if (extDef.isModifier()) { theEventWriter.writeStartElement("modifierExtension"); } else {// ww w . ja v a 2 s .co m theEventWriter.writeStartElement("extension"); } String elementId = getCompositeElementId(nextValue); if (isNotBlank(elementId)) { theEventWriter.writeAttribute("id", elementId); } theEventWriter.writeAttribute("url", extensionUrl); encodeChildElementToStreamWriter(theResource, theEventWriter, nextValue, childName, childDef, null, theContainedResource, nextChildElem); theEventWriter.writeEndElement(); }
From source file:net.solarnetwork.web.support.SimpleXmlHttpMessageConverter.java
private void writeElement(String name, Map<?, ?> props, XMLStreamWriter writer, boolean close) throws IOException, XMLStreamException { writer.writeStartElement(name);/*from ww w. jav a 2 s .c om*/ Map<String, Object> nested = null; if (props != null) { for (Map.Entry<?, ?> me : props.entrySet()) { String key = me.getKey().toString(); Object val = me.getValue(); if (propertySerializerRegistrar != null) { val = propertySerializerRegistrar.serializeProperty(name, val.getClass(), props, val); } if (val instanceof Date) { SimpleDateFormat sdf = SDF.get(); Date date = (Date) val; val = sdf.format(date); } else if (val instanceof Collection) { if (nested == null) { nested = new LinkedHashMap<String, Object>(5); } nested.put(key, val); val = null; } else if (val instanceof Map<?, ?>) { if (nested == null) { nested = new LinkedHashMap<String, Object>(5); } nested.put(key, val); val = null; } else if (classNamesAllowedForNesting != null && !(val instanceof Enum<?>)) { for (String prefix : classNamesAllowedForNesting) { if (val.getClass().getName().startsWith(prefix)) { if (nested == null) { nested = new LinkedHashMap<String, Object>(5); } nested.put(key, val); val = null; break; } } } if (val != null) { writer.writeAttribute(key, val.toString()); } } } if (nested != null) { for (Map.Entry<String, Object> me : nested.entrySet()) { outputObject(me.getValue(), me.getKey(), writer); } } if (close) { writer.writeEndElement(); } }