Skip to main content



      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 15:01 Go to next message
Eclipse UserFriend
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 15:16 Go to previous messageGo to next message
Eclipse UserFriend
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 15:18 Go to previous message
Eclipse UserFriend
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: Tue Jul 22 20:28:05 EDT 2025

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

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

Back to the top