forked from akka/alpakka
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
354 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
xml/src/test/java/akka/stream/alpakka/xml/javadsl/XmlHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (C) 2016-2018 Lightbend Inc. <http://www.lightbend.com> | ||
*/ | ||
|
||
package akka.stream.alpakka.xml.javadsl; | ||
|
||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Node; | ||
|
||
import javax.xml.transform.*; | ||
import javax.xml.transform.dom.DOMSource; | ||
import javax.xml.transform.stream.StreamResult; | ||
import java.io.StringWriter; | ||
|
||
public class XmlHelper { | ||
|
||
public static String asString(Node node) { | ||
StringWriter writer = new StringWriter(); | ||
try { | ||
Transformer trans = TransformerFactory.newInstance().newTransformer(); | ||
trans.setOutputProperty(OutputKeys.INDENT, "no"); | ||
trans.setOutputProperty(OutputKeys.VERSION, "1.0"); | ||
if (!(node instanceof Document)) { | ||
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); | ||
} | ||
trans.transform(new DOMSource(node), new StreamResult(writer)); | ||
} catch (final TransformerConfigurationException ex) { | ||
throw new IllegalStateException(ex); | ||
} catch (final TransformerException ex) { | ||
throw new IllegalArgumentException(ex); | ||
} | ||
return writer.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.