Latest web development tutorials

XML 스키마 모든 요소

> <요소가 상관> 요소는 우리에게 XML 문서의 스키마에 의해 지정되지 않은 확장 할 수있는 기능을 제공!


H2> <어떤> 요소

요소가 <없음> 요소는 우리에게 XML 문서의 스키마에 의해 지정되지 않은 확장 할 수있는 기능을 제공!

다음 예에서 "family.xsd"라는 XML 스키마에서 조각을 인용. 그것은 "사람"요소에 대한 선언을 보여줍니다. 의 <모든> 요소를 사용하여, 우리는 (의 <LASTNAME>) 모든 요소를 ​​사용할 수있는 확장 된 "사람"요소 후 :

<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:any minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>

이제, 우리는 "사람"요소를 확장하기 위해 "어린이"요소를 사용하려고합니다. 스키마의 저자는 위의 모든 "어린이"요소를 선언하지 않는 경우에도 이러한 상황에서 우리는 그것을 할 수 있습니다.

"children.xsd"라는 이름이 스키마 파일 봐 :

<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">

<xs:element name="children">
<xs:complexType>
<xs:sequence>
<xs:element name="childname" type="xs:string"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

( "Myfamily.xml"라는) 다음 XML 파일은 두 개의 다른 스키마 성분 "family.xsd"및 "children.xsd"데이터를 사용했을

<?xml version="1.0" encoding="ISO-8859-1"?>

<persons xmlns="http://www.microsoft.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.microsoft.com family.xsd
http://www.w3schools.com children.xsd">

<person>
<firstname>Hege</firstname>
<lastname>Refsnes</lastname>
<children>
<childname>Cecilie</childname>
</children>
</person>

<person>
<firstname>Stale</firstname>
<lastname>Refsnes</lastname>
</person>

</persons>

XML 파일 스키마 "family.xsd"에 기인하는 유효보다도 우리는 "사람"요소를 확장 "LASTNAME"요소 선택 요소 후 허용했다.

<없음> 및 <anyAttribute> 확장 문서를 생성하는데 사용될 수있다! 이들은 추가 요소를 통해 메인 XML 스키마에 대한 설명을 포함하고 있지 않은 문서를 만들 수있는 능력을 가지고있다.