cancel
Showing results for 
Search instead for 
Did you mean: 

Store output xml in FILE

Former Member
0 Kudos

Hi All,

I want to store the output XML in file

but file isn't create

what's the reason?

and if you have a solution

regards

Yossi

String xmlFile = "yossi.xml";

File file = new File(xmlFile);

/////////////////////////////

//Creating an empty XML Document

//We need a Document

DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();

DocumentBuilder docBuilder = dbfac.newDocumentBuilder();

Document doc = docBuilder.newDocument();

TransformerFactory transfac = TransformerFactory.newInstance();

Transformer trans = transfac.newTransformer();

trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");

trans.setOutputProperty(OutputKeys.INDENT, "yes");

//create string from xml tree

StreamResult result = new StreamResult(file);

DOMSource source = new DOMSource(doc);

trans.transform(source, result);

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Can you add a statement that prints the absolute file name of the output file? Is the file created at this path?

Armin

Former Member
0 Kudos

To Sumit

Because I need the file to apply Network UI Element

and for Network I nedd XML File

unless you know method that i can read the XML from the memory

to the NetWork

Regards

Yossi

Former Member
0 Kudos

Yossi why not u create a blank XML file and then put XML String in it....

i applied this approach and its working fine...

regards,

Sumit Malhotra

Former Member
0 Kudos

Hi Ayyapparaj

Thonk you for answer

but it's not working

Do you have anoter solution?

Regards

Yossi

Former Member
0 Kudos

Hi,

It seems that you dont have rights.

Try with the following code


String fileName = WDURLGenerator.getResourcePath(wdComponentAPI.getDeployableObjectPart(),"yossi.xml");

File file = new File(fileName);

/////////////////////////////
//Creating an empty XML Document

//We need a Document
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
Document doc = docBuilder.newDocument();

TransformerFactory transfac = TransformerFactory.newInstance();
Transformer trans = transfac.newTransformer();
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
trans.setOutputProperty(OutputKeys.INDENT, "yes");

//create string from xml tree


StreamResult result = new StreamResult(file);
DOMSource source = new DOMSource(doc);
trans.transform(source, result);

Regards

Ayyapparaj