-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXmlReader.java
More file actions
53 lines (31 loc) · 1.65 KB
/
XmlReader.java
File metadata and controls
53 lines (31 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package jdbcconnection;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class XmlReader {
private static String xmlInputFileName="test.xml";
private static String XsltBeginning="<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>";
private static String XsltPartOmitXmlDeclaration="<xsl:output method='text' indent='yes' omit-xml-declaration='yes'/>";
private static String XsltPart2="<xsl:template match='/'><xsl:value-of select='";
private static String XsltPart3="'/></xsl:template></xsl:stylesheet>";
public static void main(String[] args) throws Exception {
transformXml("InvestmentVehicle/Operation/InvestmentVehicleName");
}
public static void transformXml(String xmlPath) throws Exception{
String xsltFinal = XsltBeginning+XsltPartOmitXmlDeclaration+XsltPart2+xmlPath+XsltPart3;
Source xmlSource=new StreamSource(xmlInputFileName);
Source xsltSource=new StreamSource(new StringReader(xsltFinal));
// System.out.println(xsltFinal);
TransformerFactory transFact=TransformerFactory.newInstance();
Transformer trans=transFact.newTransformer(xsltSource);
StringWriter writer =new StringWriter();
trans.transform(xmlSource, new StreamResult(writer));
String output=writer.toString();
System.out.println("output is:"+output);
}
}