jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1540861 - /jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java
Date Mon, 11 Nov 2013 21:59:34 GMT
Author: pmouawad
Date: Mon Nov 11 21:59:33 2013
New Revision: 1540861

URL: http://svn.apache.org/r1540861
Log:
Bug 55610 - View Results Tree : Add an XPath Tester
Bugzilla Id: 55610

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java

Modified: jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java?rev=1540861&r1=1540860&r2=1540861&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java Mon Nov 11 21:59:33 2013
@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintWriter;
+import java.io.StringReader;
 import java.io.StringWriter;
 import java.util.List;
 
@@ -30,10 +31,12 @@ import javax.xml.parsers.DocumentBuilder
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Source;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.stream.StreamResult;
 
 import org.apache.jmeter.assertions.AssertionResult;
@@ -424,4 +427,25 @@ public class XPathUtil {
                     .toString());
         }
     }
+    
+    /**
+     * Formats XML
+     * @param xml
+     * @return String formatted XML
+     */
+    public static final String formatXml(String xml){
+        try {
+            Transformer serializer= TransformerFactory.newInstance().newTransformer();
+            serializer.setOutputProperty(OutputKeys.INDENT, "yes");
+            serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
+            Source xmlSource=new SAXSource(new InputSource(new StringReader(xml)));
+            StringWriter stringWriter = new StringWriter();
+            StreamResult res =  new StreamResult(stringWriter);            
+            serializer.transform(xmlSource, res);
+            return stringWriter.toString();
+        } catch (Exception e) {
+            return xml;
+        }
+    }
+
 }
\ No newline at end of file



Mime
View raw message