programing

XML과 XSD의 차이점은 무엇입니까?

nasanasas 2020. 8. 14. 07:53
반응형

XML과 XSD의 차이점은 무엇입니까?


XML (Extensible Markup Language)과 XSD (XML Schema)의 차이점은 무엇입니까?


실제로 XSD는 XML 자체입니다. 그 목적은 다른 XML 문서의 구조를 확인하는 것입니다. XSD는 모든 XML에 필수는 아니지만 XML이 특정 목적으로 사용될 수 있음을 보장합니다. XML에는 적절한 형식과 구조의 데이터 만 포함됩니다.



예를 들어

<root>
  <parent>
     <child_one>Y</child_one>
     <child_two>12</child_two>
  </parent>
</root>

이를 위해 xsd를 설계하십시오.

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" 
xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="root">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="parent">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="child_one" type="xs:string" />
              <xs:element name="child_two" type="xs:int" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>


XSD로 불가능한: 목록이 매우 작기 때문에 먼저 작성하고 싶습니다 .
1) 다른 노드 / 속성의 값을 사용하여 노드 / 속성을 검증 할 수 없습니다.
2) 제한 사항 : XSD 파일에 정의 된 요소는 하나의 데이터 유형으로 만 정의되어야합니다. [위의 예 <child_two>에서 다른 <parent>노드 나타나는 경우 int 이외의 데이터 유형은 정의 할 수 없습니다.
3) 요소와 속성의 유효성 검사를 무시할 수 없습니다. 즉, 요소 ​​/ 속성이 XML에 표시되는 경우 해당 XSD에서 잘 정의되어야합니다. 사용은 <xsd:any>허용하지만 자체 규칙이 있습니다. 이를 준수하면 유효성 검사 오류가 발생합니다. 비슷한 접근 방식을 시도했지만 성공하지 못했습니다. 여기에 Q & A가 있습니다.


XSD로 가능한 것 :
1) XML 노드의 적절한 계층 구조를 테스트 할 수 있습니다. [xsd는 어떤 자식이 어떤 부모 아래에 와야하는지 정의합니다. 어떤 자식이 오류로 간주되는지를 준수합니다. 위의 예에서 child_two는 루트의 직계 자식이 될 수 없지만 차례로 "부모"태그의 자식입니다. "루트"노드의 자식, 계층 구조가 있습니다.]
2) 노드 값의 데이터 타입을 정의 할 수 있습니다. [위의 예에서 child_two는 숫자 이외의 데이터를 가질 수 없습니다.]
3) 사용자 정의 데이터 유형 도 정의 할 수 있습니다. [예 : node <month>의 경우 가능한 데이터는 12 개월 중 하나 일 수 있습니다 .. 따라서 12 개월을 모두 정의해야합니다. 모든 12 개월 이름을 열거 형 값으로 쓰는 새 데이터 유형에서 ..
4) minOccurs 및 maxOccurs를 사용하여 요소 발생을 제한 할 수 있으며 기본값은 1과 1입니다.

.. 그리고 더 많은 ...


XSD :
XSD (XML 스키마 정의)는 XML (Extensible Markup Language) 문서의 요소를 공식적으로 설명하는 방법을 지정합니다.
Xml :
XML은 데이터설명 하도록 설계되었으며 소프트웨어 및 하드웨어와 독립적입니다.
다음 사항을 향상시킵니다.
-데이터 공유.
-플랫폼 독립적.
-데이터 가용성 증대.

차이점 :

  1. XSD는 XML을 기반으로 작성되었습니다.

  2. XSD는 문서에 나타날 수있는 요소와 구조를 정의하지만 XML은 그렇지 않습니다.

  3. XSD는 데이터가 올바르게 해석되도록 보장하지만 XML은 그렇지 않습니다.

  4. An XSD document is validated as XML, but the opposite may not always be true.

  5. XSD is better at catching errors than XML.

An XSD defines elements that can be used in the documents, relating to the actual data with which it is to be encoded.
for eg:
A date that is expressed as 1/12/2010 can either mean January 12 or December 1st. Declaring a date data type in an XSD document, ensures that it follows the format dictated by XSD.


XML versus XSD

XML defines the syntax of elements and attributes for structuring data in a well-formed document.

XSD (aka XML Schema), like DTD before, powers the eXtensibility in XML by enabling the user to define the vocabulary and grammar of the elements and attributes in a valid XML document.


SIMPLE XML EXAMPLE:

<school>
  <firstname>John</firstname>
  <lastname>Smith</lastname>
</school>

XSD OF ABOVE XML:

<xs:element name="school">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="firstname" type="xs:string"/>
      <xs:element name="lastname" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

Here:

complex type: denotes it contains other elements. simple type: denotes they do not contain other elements.

type: string, decimal, integer, boolean, date, time,

In simple words, xsd is another way to represent and validate XML data with the specific type.With the help of extra attributes, we can perform multiple operations. performing any task on xsd is simpler than xml.


Basically an XSD file defines how the XML file is going to look like. It's a Schema file which defines the structure of the XML file. So it specifies what the possible fields are and what size they are going to be.

An XML file is an instance of XSD as it uses the rules defined in the XSD.


XML has a much wider application than f.ex. HTML. It doesn't have an intrinsic, or default "application". So, while you might not really care that web pages are also governed by what's allowed, from the author's side, you'll probably want to precisely define what an XML document may and may not contain.

It's like designing a database.

The thing about XML technologies is that they are textual in nature. With XSD, it means you have a data structure definition framework that can be "plugged in" to text processing tools like PHP. So not only can you manipulate the data itself, but also very easily change and document the structure, and even auto-generate front-ends.

Viewed like this, XSD is the "glue" or "middleware" between data (XML) and data-processing tools.

참고URL : https://stackoverflow.com/questions/2333998/what-is-the-difference-between-xml-and-xsd

반응형