Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Create a new xml file from java code
Create a new xml file from java code [message #846090] Sun, 15 April 2012 19:01 Go to next message
Davide M is currently offline Davide MFriend
Messages: 17
Registered: April 2012
Junior Member
Hi,

I like to parse the java code with jdt and then write by code some xml or other file. Im am using this code:

IPackageFragment ppp = xfragmentRoot.createPackageFragment(gen.packageName, false, null);
ppp.createCompilationUnit(gen.name, gen.content.toString(), true, null);

If I try to create a xml file (i.e. gen.name = "abc.xml"), the this exception is throw:

Caused by: Java Model Exception: Java Model Status [Invalid name specified: abc.xml]
at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:784)
at org.eclipse.jdt.internal.core.PackageFragment.createCompilationUnit(PackageFragment.java:145)



How can I write a xml (or other extensions)?

Thanks in advance for help!
Re: Create a new xml file from java code [message #846100 is a reply to message #846090] Sun, 15 April 2012 19:16 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1051
Registered: July 2009
Senior Member
Compilation Units are for Java source files, only.
Hence .xml is not accepted as the extension.

For other files use types below org.eclipse.core.resources.IResource.

Starting from an IPackageFragment you may want to do s.t. like
  IFolder packageFolder = pkg.getResource();
  IFile file = packageFolder.getFile(new Path(...));
  file.create(..);


HTH,
Stephan
Re: Create a new xml file from java code [message #846803 is a reply to message #846100] Mon, 16 April 2012 19:18 Go to previous message
Davide M is currently offline Davide MFriend
Messages: 17
Registered: April 2012
Junior Member
Work! Many thanks!
Previous Topic:get rid of -Djava.endorsed.dirs="/opt/local/share/java/tomcat6/endorsed"
Next Topic:Using Method Invocation Visitor
Goto Forum:
  


Current Time: Sat Dec 20 21:45:01 GMT 2014

Powered by FUDForum. Page generated in 0.01575 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software