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.

如果您使用Web服务 ,则必须一直在使用XSD。 要测试Web服务,您需要从XSD文件生成XML。

从XSD生成XML (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.

我们可以使用Eclipse IDE轻松地从XSD文件生成XML。 只需按照以下步骤从XSD获取XML。

  1. Select XSD File in project, right click for Menu and select Generate > XML File…在项目中选择XSD文件,右键单击菜单,然后选择生成> XML文件…
  2. Provide the XML file Name and XML File location in the popup window. Click on next button.在弹出窗口中提供XML文件名和XML文件位置。 单击下一步按钮。
  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.选择要为其生成示例XML文件的根元素,确保选中“创建可选属性”和“创建可选元素”的复选框。 下图显示了窗口的外观。
  4. 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.单击完成按钮,它将为您生成具有默认值的XML文件。 现在,您可以根据需要更改值。

XSD到XML的示例 (XSD to XML Example)

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

这是我将为其生成XML文件的XSD。

Employee.xsd

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.

由于Employee.xsd具有两个根元素; empRequestempResponse ; 我可以生成两个XML文件。

Here are the XML files generated by Eclipse, the values are changed by me.

这是Eclipse生成的XML文件,值由我更改。

EmployeeRequest.xml

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

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.

我希望这个快速技巧可以帮助您轻松地从XSD生成XML。

翻译自: https://www.journaldev.com/821/generate-xml-xsd-eclipse-java

如何在Eclipse中从XSD生成XML相关推荐

  1. 如何在Java中针对XSD验证XML

    Java XML Validation API can be used to validate XML against XSD in java program. javax.xml.validatio ...

  2. 连接maven_如何在Eclipse中使用Maven工程连接远程的Spark

    如何在Eclipse中使用Maven工程连接远程的Spark 本地Spark跑不会出现什么问题,但是切换到服务器上各种问题. 异常 java.lang.ClassCastException: cann ...

  3. jaxb xsd生成xml_使用JAXB从XSD生成XML

    jaxb xsd生成xml 这是最初由JCG合作伙伴 Experiences Unlimited的Mohamed Sanaulla发表的帖子. Mohamed解释了如何使用JAXB从给定的XSD生成X ...

  4. 使用JAXB从XSD生成XML

    这是最初由JCG合作伙伴 Experiences Unlimited的Mohamed Sanaulla发表的帖子. Mohamed解释了如何使用JAXB从给定的XSD生成XML . (注意:对原始帖子 ...

  5. 浅析如何在Nancy中使用Swagger生成API文档

    原文:浅析如何在Nancy中使用Swagger生成API文档 前言 上一篇博客介绍了使用Nancy框架内部的方法来创建了一个简单到不能再简单的Document.但是还有许许多多的不足. 为了能稍微完善 ...

  6. eclipse 导入项目_JAVA编程实战:坦克大战系列2-坦克如何在eclipse中编写

    游戏中寻找学习JAVA的乐趣之 坦克大战系列2-坦克如何在Eclipse中编写 前言 本篇主要对Robocode在eclipse中如何配置并编写. Eclipse中的配置 通过本身自带的编辑器去写代码 ...

  7. 如何在Eclipse中添加Servlet-api.jar的方法

    方法一: 点击窗口->首选项->java->构建路径->类路径变量->新建: 将你的tomcat目录下的common/lib/servlet.jar加进来. 如果你建立了 ...

  8. 面试官问我:如何在 Python 中解析和修改 XML

    摘要:我们经常需要解析用不同语言编写的数据.Python提供了许多库来解析或拆分用其他语言编写的数据.在此 Python XML 解析器教程中,您将学习如何使用 Python 解析 XML. 本文分享 ...

  9. 如何在eclipse中导入Java项目文件包(方法截图详细步骤)

    如何在eclipse中导入Java项目文件包 首先新创建一个Java项目 第二步导入到我们新创建的Java项目文件包中 首先新创建一个Java项目 首先点击file->再点击new->点击 ...

最新文章

  1. application配置token_Kerrigan:配置中心管理UI的实现思路和技术细节
  2. mysql中两根竖线什么意思_SQL如何查询表字段值以竖线分割的数据
  3. hdu4421 2-sat(枚举二进制每一位)
  4. vm ububtu突然没网
  5. leetcode 640. Solve the Equation | 640. 求解方程(字符串处理)
  6. 2010年IT人士必去的10个网站
  7. 快速理解网络通信协议
  8. java对焦_相机的对焦与合焦
  9. TextBoxWatermarkExtender扩展器与RequiredFieldValidator控件相冲突的解决方案
  10. [UML]UML系列——时序图(顺序图)sequence diagram
  11. 转贴: mysql-5.7.20 编码由 utf8 改为 utf8mb4
  12. docker镜像与容器的区别
  13. jQuery end()函数示例
  14. python可以用来写导航吗_在python中使用selenium进行导航
  15. 计算机出现假桌面怎么解决办法,Win10系统因为“AppHangXProcB1”造成桌面不停假死怎么处理...
  16. 《学习的本质》读后感
  17. 电子邮件格式详细介绍
  18. 快速批量下载 B 站视频
  19. C++与C#相比,哪个更适合开发大型游戏?
  20. 二十岁的男人(应该需要做什么)

热门文章

  1. simpson积分模板
  2. android基本控件学习-----EditText
  3. 谷歌探月大赛确定29支队伍 最高奖金2000万美元
  4. [转载] Python字典中items()和iteritems()区别
  5. 你做电商死法TOP10:你中了几枪?
  6. python相关软件安装流程图解——Windows下安装Redis以及可视化工具——Redis-x64-3.2.100——redis-desktop-manager-0.9.3.817...
  7. JS编写自己的富文本编辑器
  8. java并发编程(十)使用wait/notify/notifyAll实现线程间通信
  9. 20145206《Java程序设计》实验五Java网络编程及安全
  10. c#基础(一)之内存管理