Mute xml generation from xsd with eclipse

In the latest open source versions of the Eclipse IDE, you can create XML documents from DTD and XSD files. Right-click on the specified * .dtd or * .xsd file and select "Generate → XML File ...". You can choose which root element to generate and whether additional attributes and elements should be generated.

Can I use this headless (without triggering an eclipse)?

+3
source share
2 answers

You can create a headless RCP application that contains only those plugins that are needed to create a real generation. These are basically WTP plugins with a few basic plugins needed to manage extension points, etc.

You can run the RCP application from the command line and pass arguments to the circuit to generate and the name of the output file. The production implementation lacks much of the validation you may want, but shows how this can be done. It also encodes UTF-8 encoding, you can extend the processing of arguments to make this an optional parameter or something else.

The following snippets can be included in the new headless RCP application. To create an RCP application, first create a new plugin project:

  • - > - > ...- > Plug-In Development- > Plug-in Project,
  • (, name.seller.rich.xmlgen)
  • Rich Client Application,
  • , META-INF/Manifest.MF , ( "... " )
    • org.eclipse.core.runtime,
    • org.eclipse.core.resources; = "3.5.0",
    • org.eclipse.wst.common.uriresolver; = "1.1.301",
    • org.eclipse.wst.sse.core; = "1.1.400",
    • org.eclipse.wst.xml.core; = "1.1.400",
    • org.eclipse.wst.xml.ui; = "1.1.0",
    • org.eclipse.xsd; = "2.5.0",
    • com.ibm.icu; = "4.0.1",
    • org.eclipse.wst.xsd.core; = "1.1.401",
    • org.eclipse.wst.xsd.ui; = "1.2.204",
    • org.eclipse.emf.ecore; = "2.5.0"
  • Application, Java start() Application ( ).

    import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; java.io.FileWriter; import java.net.URI; import java.net.URL;

    import org.eclipse.core.internal.utils.FileUtil; import org.eclipse.core.runtime.Platform; import org.eclipse.emf.ecore.plugin.EcorePlugin; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; import org.eclipse.wst.xml.ui.internal.wizards.NewXMLGenerator;

    public ( IApplicationContext) Exception {   String [] args = Platform.getCommandLineArgs();

    String schemaFileName = args[0];// e.g. "C:\test\test.xsd"
    String xmlFileName = args[1];// e.g. "C:\test\test.xml"
    String rootName = args[2];//"myTestRoot";
    String charsetName = "UTF-8";
    
    try {
        //get the URI as a full URL path
        URI schemaUri = new File(schemaFileName).toURI();
        schemaFileName = schemaUri.toURL().toString();
    
        //TODO handle any errorInfo set into this array
        String[] errorInfo = new String[2];
        CMDocument cmDocument = NewXMLGenerator.createCMDocument(schemaFileName,
                errorInfo);
        NewXMLGenerator generator = new NewXMLGenerator(schemaFileName,
                cmDocument);
    
        generator.setRootElementName(rootName);
    
        ByteArrayOutputStream out = generator.createXMLDocument(xmlFileName,
                charsetName);
    
        //output the content to the file.
        File outFile = new File(xmlFileName);
    
        outFile.getParentFile().mkdirs();
    
        FileWriter writer = new FileWriter(outFile);
    
        writer.write(out.toString(charsetName));
    
        writer.flush();
        writer.close();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    
    return IApplication.EXIT_OK;
    

    }

, .

  • - > - > ...- > - >
  • RCP
  • " " "".
  • , config.product( , ).
  • ... :, (double , - RCP-), OK

RCP.

  • - > ...- > - > Eclipse

, , , XML .

:

  • ( ).
  • ( , , , ).

, , . , , , , . , .
, .


, , Spring, Spring. Eclipse "" , . , (. help ),

, - .

:

 http://www.springframework.org/schema/beans=c:\\schema\\spring-beans.xsd
 http://www.springframework.org/schema/tool=c:\\schema\\spring-tool.xsd
+3

? , .

Sun XMLGenerator. , .

0

Source: https://habr.com/ru/post/1718885/


All Articles