// Tutorial //

How to Generate XML from XSD in Eclipse

Published on August 3, 2022
Default avatar
By Pankaj
Developer and author at DigitalOcean.
How to Generate XML from XSD in Eclipse

While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.

If you work on web services, you must have been using XSD. To test the web service, you need to generate XML from XSD file.

Generate XML from XSD

We can use Eclipse IDE to easily generate XML from the XSD file. Just follow the below steps to get XML from XSD.

  1. Select XSD File in project, right click for Menu and select Generate > XML File…
  2. Provide the XML file Name and XML File location in the popup window. Click on next button.
  3. Select the root element for which you want to generate the sample XML file, make sure to select checkboxes for “Create optional attributes” and “Create optional elements”. Below image shows how the window will look. generate xml from xsd5. Click on Finish button and it will generate the XML File for you with the default values. Now you can change the values according to your requirement.

XSD to XML Example

Here is the XSD for which I will be generating XML files. Employee.xsd

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="https://www.w3.org/2001/XMLSchema" 
targetNamespace="https://www.journaldev.com/Employee" 
xmlns:empns="https://www.journaldev.com/Employee" elementFormDefault="qualified">

	<element name="empRequest" type="empns:empRequest"></element>
	
	<element name="empResponse" type="empns:empResponse"></element>

	<complexType name="empRequest">
		<sequence>
			<element name="id" type="int"></element>
		</sequence>
	</complexType>
	
	<complexType name="empResponse">
		<sequence>
			<element name="id" type="int"></element>
			<element name="role" type="string"></element>
			<element name="fullName" type="string"></element>
		</sequence>
	</complexType>
</schema>

Since Employee.xsd has two root elements; empRequest and empResponse; I can generate two XML files. Here are the XML files generated by Eclipse, the values are changed by me. EmployeeRequest.xml

<?xml version="1.0" encoding="UTF-8"?>
<empns:empRequest xmlns:empns="https://www.journaldev.com/Employee" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.journaldev.com/Employee Employee.xsd ">
  <empns:id>5</empns:id>
</empns:empRequest>

EmployeeResponse.xml

<?xml version="1.0" encoding="UTF-8"?>
<empns:empResponse xmlns:empns="https://www.journaldev.com/Employee" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.journaldev.com/Employee Employee.xsd ">
  <empns:id>1</empns:id>
  <empns:role>Developer</empns:role>
  <empns:fullName>Pankaj Kumar</empns:fullName>
</empns:empResponse>

I hope this quick tip will help you in generating XML from XSD easily.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us


About the authors
Default avatar
Pankaj

author

Developer and author at DigitalOcean.

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
JournalDev
DigitalOcean Employee
DigitalOcean Employee badge
February 2, 2021

This command is not available anymore in latest Eclipse version (2020-12). Is there any plugin I need?

- Fish

    JournalDev
    DigitalOcean Employee
    DigitalOcean Employee badge
    January 10, 2021

    Hi, nice Article. I have a question, how can we compare a xml file with the XSD ? Is there any way to check if the xml is according to the XD provided?

    - Ishita Rawat

      JournalDev
      DigitalOcean Employee
      DigitalOcean Employee badge
      April 12, 2017

      I want to implement this by java coding. Any idea how eclipse internally using which logic ?

      - Sumit sarkar

        JournalDev
        DigitalOcean Employee
        DigitalOcean Employee badge
        April 11, 2017

        HI Pankaj, I am trying to build a web service in eclipse for ordering food, I have created an XML schema and XML document. Are these the next steps: Create a dynamic web project, create web service provider java class, create a web service, web service client creation, deploy web service and client then test web service. I am struggling on the java class section because all examples are pre-made and I don’t know java. Or is there any other way to build a web service with an xml schema?? or otherwise why would one build a schema, what use is it?

        - Rusty

          JournalDev
          DigitalOcean Employee
          DigitalOcean Employee badge
          March 30, 2017

          Hi I have requirement.Data populate from anywhere like txt file or excel to XML using XSD

          - sanjay

            JournalDev
            DigitalOcean Employee
            DigitalOcean Employee badge
            May 15, 2015

            Very good, short and to the point example. Thank you.

            - Suresh

              JournalDev
              DigitalOcean Employee
              DigitalOcean Employee badge
              September 10, 2014

              Hi, I have requirement to generate java classes from XML. How can i achieve this? and how to generate XML schema from XML file. ? In Eclipse IDE. please replay me to the below email Id. santhosh.ks1986@gmail.com, Thanks in advance.

              - Santhosh K S

                JournalDev
                DigitalOcean Employee
                DigitalOcean Employee badge
                August 26, 2014

                I have an xsd file open in eclipse and can also see in the files navigator. But, there is no option to generate xml when I right click the file.

                - Vijay Inani

                  JournalDev
                  DigitalOcean Employee
                  DigitalOcean Employee badge
                  July 23, 2014

                  Good article. Do you have any idea How to generate xml from dtd ?

                  - john

                    JournalDev
                    DigitalOcean Employee
                    DigitalOcean Employee badge
                    March 5, 2014

                    Wow, it was just what I’ve been searching for days, just what I needed to implement some webservices. Thank you!

                    - Felipe

                      Try DigitalOcean for free

                      Click here to Sign up and get $200 of credit to try our products over 60 days!