I'm using Saxon parser to split the big file into smaller ones. Below is my sample code,
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory
.newTransformer(new StreamSource(new File(xsltPath)));
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
transformer.transform(new StreamSource(new File(sourcePath)),
new StreamResult(new File(resultDir)));
Where sourcePath = C:/path/Temp/AppModule.xml xsltPath = C:/path/Temp/create-fragment.xslt resultDir = C:/path/Temp/
This code splits the AppModule.xml into smaller xml files perfectly but with exception in the console,
Error java.io.FileNotFoundException: C:\path\Temp (Access is denied) net.sf.saxon.trans.XPathException: java.io.FileNotFoundException: C:\path\Temp (Access is denied)
I googled and found that I should specify the exact file name to new File() method. But as you see, the file name i do not know at compile time, only during run time the parser identifies the input AppModule.xml and split the xml into smaller files with the name of value tag in it.
AppModule.xml
<?xml version='1.0' encoding='UTF-8'?>
<data>
<value>A1</value>
<value>B1</value>
<value>C1</value>
<value>A2</value>
<value>B2</value>
<value>C2</value>
</data>
OutPut: A1.xml:
<?xml version="1.0" encoding="UTF-8"?>
<test>A1</test>
Similarly it will create B1,c1,A2,B2,C2 files correspondingly.
Please share your valuable comments.
File
handles. See: "How to scan a folder in Java" – Ceiling Gecko