Use the xsd.exe command to generate the corresponding XSD Schema File Based on the specified XML file

Source: Internet
Author: User
Tags create xml schema

Open the vs command window,

Enter the command: XSD file. xml [/outputdir: Directory] [/parameters: file. xml]

Example:

Appendix 1: categories. xml

 <?  XML  Version  = " 1.0 " Encoding  = " UTF-8 " ?> <  Categories  >  < Category  > <  ID  > 2 </  ID  > <  Visible  > True </  Visible  > <  Title  > News Classification </  Title  > < Description  > </  Description  > <  Parentid  > </  Parentid  > </  Category  >  <  Category  > <  ID  > 0001 </  ID > <  Visible  > True </  Visible  > <  Title  > News Classification 1 </  Title  > <  Description  > Test 1 ~ </  Description  > < Parentid  > 2 </  Parentid  > </  Category  > <  Category  > <  ID  > 0002 </  ID  > <  Visible  > True </ Visible  > <  Title  > News classification II </  Title  > <  Description  > Test 2 ~ </  Description  > <  Parentid  > 2 </  Parentid > </  Category  > </  Categories  > 
 
 
 
Appendix 2: converted categories. XSD
 
Note: After conversion, the file content may be slightly modified. The type attribute of the element in the converted file is "XS: string" by default"
 
Here, change the type attribute of visible to"Xs: Boolean"
 <?  XML  Version  = " 1.0 " Encoding  = " UTF-8 " ?> <  Xs: Schema  ID  = " Categories " Xmlns  = "" Xmlns: XS  = " Http://www.w3.org/2001/XMLSchema " Xmlns: msdata  = "URN: Schemas-Microsoft-com: XML-msdata " > <  Xs: Element  Name  = " Categories " Msdata: isdataset  = " True " Msdata: locale  = " En-US " > <  Xs: complextype  > < Xs: Choice  Minoccurs  = " 0 " Maxoccurs  = " Unbounded " > <  Xs: Element  Name  = " Category " > <  Xs: complextype  > < Xs: Sequence  > <  Xs: Element  Name  = " ID " Type  = " Xs: String " Minoccurs  = " 0 " /> <  Xs: Element  Name  = "Visible " Type  = " Xs: Boolean " Minoccurs  = " 0 " />  <! --  Note:  -->  <  Xs: Element  Name  = " Title "Type  = " Xs: String " Minoccurs  = " 0 " /> <  Xs: Element  Name  = " Description " Type  = " Xs: String " Minoccurs  = "0 " /> <  Xs: Element  Name  = " Parentid " Type  = " Xs: String " Minoccurs  = " 0 " /> </  Xs: Sequence  > </ Xs: complextype  > </  Xs: Element  > </  Xs: Choice  > </  Xs: complextype  > </  Xs: Element  > </  Xs: Schema  > 

 

---------

Note: If the XML file is not automatically generated, you can also use "create XML schema file" to create a new XSD file, as shown below:

 <?  XML Version  = " 1.0 " Encoding  = " UTF-8 " ?> <  Xs: Schema  ID  = " XMLSCHEMA " 
    Targetnamespace =" Http://tempuri.org/XMLSchema.xsd"  <! -- This sentenceCodeNeed to be deleted. Otherwise, XML data cannot be read through dataset. Why? Remove to display --> 
         Elementformdefault  = " Qualified " Xmlns  = " Http://tempuri.org/XMLSchema.xsd " Xmlns: mstns  = "Http://tempuri.org/XMLSchema.xsd " Xmlns: XS  = " Http://www.w3.org/2001/XMLSchema " > </  Xs: Schema  > 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.