
xml转xsd
XSD or XML Schema Definition is a schema definition document which will provide the definition of different type of objects and entities in XML language. XSD is very popular for data exchange especially in enterprise environments because of different advantages. In this tutorial, we will examine XSD, XSD syntax, XSD usage.
XSD或XML架构定义是一个架构定义文档,它将提供XML语言中不同类型的对象和实体的定义。 XSD由于具有不同的优势而在数据交换中非常流行,尤其是在企业环境中。 在本教程中,我们将研究XSD,XSD语法和XSD用法。
什么是XML? (What Is XML?)
Before explaining the XSD we should explain the XML language. XML the short form of the eXtensible Markup Language which is designed to extend different data types in a structured manner. XML is very popular because of its clarity and structured definition. Below we can find some XML statements.
在解释XSD之前,我们应该解释XML语言。 XML可扩展标记语言的缩写,旨在以结构化方式扩展不同的数据类型。 XML由于其清晰和结构化定义而非常受欢迎。 下面我们可以找到一些XML语句。
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
什么是XML模式? (What Is XML Schema?)
XML Schema is the complete XML document that describes the XML document. XML schema contains the version, schema URI data types, etc. Below we can see a complete XML schema that simply defines the Person
entity.
XML模式是描述XML文档的完整XML文档。 XML模式包含版本,模式URI数据类型等。在下面,我们可以看到完整的XML模式,该模式简单地定义了Person
实体。
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Person">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="surname" type="xs:string"/>
<xs:element name="age" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
什么是XML模式定义? (What Is XML Schema Definition?)
Well, actually we have learned the XSD or XML Schema Definition because the XML Schema language also named XSD. A typical XSD contains the following elements and information about the XML.
好吧,实际上我们已经学习了XSD或XML Schema定义,因为XML Schema语言也称为XSD。 典型的XSD包含以下元素和有关XML的信息。
Elements
that can appear in an XML document.可以出现在XML文档中的
Elements
。Attributes
that can be used for elements in an XML document.可用于XML文档中元素的
Attributes
。Data Types
for defined elements and attributes.定义的元素和属性的
Data Types
。- Default and fixed values for elements and attributes. 元素和属性的默认值和固定值。
XSD
version will set the XML version.XSD
版本将设置XML版本。
XSD语法 (XSD Syntax)
XSD has a very structured syntax. As a markup language like HTML, most of the elements are defined with start and end tags. XSD express the hierarchy between elements in order to create a child and parent relation. This hierarchical usage provides the ability to create complex data structures easily and relate them to each other.
XSD具有非常结构化的语法。 作为类似于HTML的标记语言,大多数元素都是使用开始和结束标签定义的。 XSD表示元素之间的层次结构,以创建子关系和父关系。 这种分层用法提供了轻松创建复杂数据结构并将它们相互关联的能力。
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Person">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="surname" type="xs:string"/>
<xs:element name="age" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:element name="Person">
will create a data type named `Person` and the details will be defined inside this tag.< xs:element name ="Person" >
将创建一个名为`Person`的数据类型,详细信息将在此标记内定义。<xs:complexType
is used to create multiple different elements insidePerson
data type.< xs:complexType
用于在Person
数据类型内创建多个不同的元素。<xs:sequence>
creates a sequence where we can put multiple elements.< xs:sequence >
创建一个可以放置多个元素的序列。<xs:element name="name" type="xs:string"/>
is an element definesPerson
data type. It is named `name` and stored as a string.< xs:element name ="name" type ="xs:string" />
是定义Person
数据类型的元素。 它被命名为“ name”并存储为字符串。
在XML文档中使用XSD (Use XSD In XML Document)
We can use the XSD or XML Definition in an XML document while exchanging or storing information. The following XML document uses the previously defined Person
data type. We will just put some data into this Person object which are name, surname, age, and city.
在交换或存储信息时,我们可以在XML文档中使用XSD或XML定义。 以下XML文档使用先前定义的Person
数据类型。 我们将一些数据放入此Person对象中,这些数据是名称,姓氏,年龄和城市。
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM
"https://www.w3schools.com/xml/note.dtd">
<Person>
<name>İsmail</name>
<surname>Baydan</surname>
<age>36</age>
<city>Ankara</city>
</Person>
翻译自: https://www.poftut.com/what-is-xsd-xml-schema-definition/
xml转xsd