XSD <anyAttribute> ਐਲੀਮੈਂਟ

<anyAttribute> ਐਲੀਮੈਂਟ ਸਾਨੂੰ XML ਦਸਤਾਵੇਜ਼ ਨੂੰ ਸਕੈਮਾ ਦੁਆਰਾ ਨਿਰਧਾਰਿਤ ਪੈਰਾਮੀਟਰਾਂ ਦੇ ਬਿਨਾ ਵਧਾਉਣ ਦੀ ਸਮਰੱਥਾ ਦਿੰਦਾ ਹੈ!

<anyAttribute> ਐਲੀਮੈਂਟ

<anyAttribute> ਐਲੀਮੈਂਟ ਸਾਨੂੰ XML ਦਸਤਾਵੇਜ਼ ਨੂੰ ਸਕੈਮਾ ਦੁਆਰਾ ਨਿਰਧਾਰਿਤ ਪੈਰਾਮੀਟਰਾਂ ਦੇ ਬਿਨਾ ਵਧਾਉਣ ਦੀ ਸਮਰੱਥਾ ਦਿੰਦਾ ਹੈ!

ਇਹ ਉਦਾਹਰਣ "family.xsd" ਨਾਮ ਦੇ XML ਸਕੈਮਾ ਦਾ ਇੱਕ ਹਿੱਸਾ ਹੈ। ਇਹ ਸਾਨੂੰ "person" ਐਲੀਮੈਂਟ ਦੇ ਲਈ ਇੱਕ ਐਲਾਨ ਦਿਖਾਉਂਦਾ ਹੈ। <anyAttribute> ਐਲੀਮੈਂਟ ਦੀ ਮਦਦ ਨਾਲ, ਅਸੀਂ "person" ਐਲੀਮੈਂਟ ਨੂੰ ਕਿਸੇ ਪੈਰਾਮੀਟਰ ਦੇ ਬਿਨਾ ਕਿਸੇ ਪੈਰਾਮੀਟਰ ਨੂੰ ਜੋੜ ਸਕਦੇ ਹਾਂ:

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

ਹੁਣ, ਅਸੀਂ 'gender' ਅਤੀਤ ਦੇ ਰੂਪ ਵਿੱਚ 'person' ਅਤੀਤ ਨੂੰ ਵਧਾਉਣ ਦੀ ਕੋਸ਼ਿਸ਼ ਕਰਦੇ ਹਾਂ। ਇਸ ਪਰਿਸਥਿਤੀ ਵਿੱਚ ਅਸੀਂ ਇਹ ਕਰ ਸਕਦੇ ਹਾਂ, ਭਾਵੇਂ schema ਦੇ ਲੇਖਕ ਨੇ ਕਿਸੇ ਵੀ 'gender' ਅਤੀਤ ਦੀ ਘੋਸ਼ਣਾ ਨਾ ਕੀਤੀ ਹੋਵੇ ਨਹੀਂ。

ਇਹ schema ਫਾਇਲ ਦੇਖੋ, 'attribute.xsd' ਨਾਮ ਦੀ:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.codew3c.com"
xmlns="http://www.codew3c.com"
elementFormDefault="qualified">
<xs:attribute name="gender">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="male|female"/>
    </xs:restriction>
  </xs:simpleType>
</xs:attribute>
</xs:schema>

ਇਹ XML ('Myfamily.xml' ਨਾਮ ਦਾ), ਵੱਖ-ਵੱਖ schema ਦੇ ਭਾਗਾਂ ਦਾ ਇਸਤੇਮਾਲ ਕਰਦਾ ਹੈ, 'family.xsd' ਅਤੇ 'attribute.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.codew3c.com attribute.xsd">
<person gender="female">
<firstname>Jane</firstname>
<lastname>Smith</lastname>
</person>
<person gender="male">
<firstname>David</firstname>
<lastname>Smith</lastname>
</person>
</persons>

ਉੱਪਰ ਦਾ ਇਹ XML ਫਾਈਲ ਵੈਧ ਹੈ ਕਿਉਂਕਿ schema "family.xsd" ਸਾਨੂੰ "person" ਐਲੀਮੈਂਟ ਵਿੱਚ ਗੁਣ ਜੋੜਨ ਦੀ ਇਜਾਜ਼ਤ ਦਿੰਦਾ ਹੈ。

<any> ਅਤੇ <anyAttribute> ਹਰ ਦੋਵੇਂ ਵਿਸਤਾਰਯੋਗ ਦਸਤਾਵੇਜ਼ ਬਣਾਉਣ ਲਈ ਵਰਤੇ ਜਾ ਸਕਦੇ ਹਨ! ਉਹ ਦਸਤਾਵੇਜ਼ ਨੂੰ ਮੁੱਖ XML schema ਵਿੱਚ ਘੋਸ਼ਿਤ ਨਾ ਕੀਤੇ ਗਏ ਅਤਿਰਿਕਤ ਐਲੀਮੈਂਟ ਸਮੇਤ ਰੱਖਣ ਦੀ ਸਮਰੱਥਾ ਦਿੰਦੇ ਹਨ。