@Override protected void marshalDomNode(Object graph, Node node) throws XmlMappingException { HierarchicalStreamWriter streamWriter; if (node instanceof Document) { streamWriter = new DomWriter((Document) node, this.nameCoder); } else if (node instanceof Element) { streamWriter = new DomWriter((Element) node, node.getOwnerDocument(), this.nameCoder); } else { throw new IllegalArgumentException("DOMResult contains neither Document nor Element"); } doMarshal(graph, streamWriter, null); }
protected void marshalDomNode(Object graph, Node node) throws XmlMappingException { HierarchicalStreamWriter streamWriter; if (node instanceof Document) { streamWriter = new DomWriter((Document) node); } else if (node instanceof Element) { streamWriter = new DomWriter((Element) node, node.getOwnerDocument(), new XmlFriendlyReplacer()); } else { throw new IllegalArgumentException("DOMResult contains neither Document nor Element"); } marshal(graph, streamWriter); }
private static Element storeGBeans(List gbeans) throws IOException { GBeanData[] gbeanDatas = (GBeanData[]) gbeans.toArray(new GBeanData[gbeans.size()]); DocumentBuilderFactory documentBuilderFactory = XmlUtil.newDocumentBuilderFactory(); DocumentBuilder documentBuilder = null; try { documentBuilder = documentBuilderFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw (IOException)new IOException("Cannot instantiate " + Document.class.getName()).initCause(e); } Document document = documentBuilder.newDocument(); DomWriter writer = new DomWriter(document); XStream xstream = XStreamUtil.createXStream(); xstream.marshal(gbeanDatas, writer); // FileWriter w = new FileWriter("target/foo.xml"); // xstream.toXML(gbeanDatas, w); // w.close(); return document.getDocumentElement(); } }
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext unmarshallingContext) { DocumentBuilderFactory documentBuilderFactory = XmlUtil.newDocumentBuilderFactory(); DocumentBuilder documentBuilder = null; try { documentBuilder = documentBuilderFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new ConversionException("Cannot instantiate " + Document.class.getName(), e); } Document document = documentBuilder.newDocument(); DomWriter writer = new DomWriter(document); copy(reader, writer); if (Document.class.isAssignableFrom(unmarshallingContext.getRequiredType())) { return document; } else { return document.getDocumentElement(); } }
public void marshal(MessageExchange exchange, NormalizedMessage message, Object body) throws MessagingException { if (useDOM) { try { Document document = transformer.createDocument(); getXStream().marshal(body, new DomWriter(document)); message.setContent(new DOMSource(document)); } catch (ParserConfigurationException e) { throw new MessagingException("Failed to marshal: " + body + " to DOM document: " + e, e); } } else { String xml = getXStream().toXML(body); message.setContent(new StringSource(xml)); } }