4
웹 서비스를 호출하는 클라이언트가 있는데 ElementNSImpl
개체가 반환됩니다. 이 개체를 String으로 변환 할 수 있습니까? org.w3c.dom.Document
객체 내가 사용했던 같은 코드를 ElementNSImpl to String
protected static String documentToString(final Document doc) {
// outputs a DOM structure to plain String
try {
StringWriter sw = new StringWriter();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.transform(new DOMSource(doc), new StreamResult(sw));
return sw.toString();
} catch (Exception ex) {
throw new RuntimeException("Error converting to String", ex);
}
}