xml生成xsd文件的方法

下载trang.jar  地址:http://download.csdn.net/detail/luoww1/8957991

将下载的包放在d:\xmlToxsd


第三步  生成XSD

假设在 d:\xmlToxsd 下有一个xml文件  person.xml

?
1
2
3
4
5
6
7
xml version = "1.0" encoding = "UTF-8" standalone = "yes" ?>
< person NAME = "ZhangSan" >   
    < address country = "China" >       
       < state >beijing state >   
    address >   
    < Job >IT Job >
person >

打开windows命令行,将当前位置变更到 d:\xmlToxsd

输入

java -jar trang.jar  person.xml  person.xsd

 (  trang.jar 接受两个参数,第一个为源文件,第二个为目标文件)

ok!你可以看到在 d:\  下就生成了 person.xsd 文件

 xml生成xsd文件的方法_第1张图片

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
xml version = "1.0" encoding = "UTF-8" ?>
< xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema" elementFormDefault = "qualified"
    < xs:element name = "person" >   
       < xs:complexType >    
         < xs:sequence >       
           < xs:element ref = "address" />       
           < xs:element ref = "Job" />     
         xs:sequence >     
         < xs:attribute name = "NAME" use = "required" type = "xs:NCName" />   
       xs:complexType >
     xs:element
     < xs:element name = "address" >   
       < xs:complexType >    
         < xs:sequence >       
           < xs:element ref = "state" />      
         xs:sequence >     
         < xs:attribute name = "country" use = "required" type = "xs:NCName" />   
       xs:complexType
     xs:element
     < xs:element na style = "color:#000000;" >me=" span >state" type="xs:NCName"/> 
     < xs:element name = "Job" type = "xs:NCName" />
xs:schema >

你可能感兴趣的:(java)