XSD <anyAttribute> 元素
<anyAttribute> ਏਲੀਮੈਂਟ ਸਾਨੂੰ ਐਕਸਟੈਂਡ ਐਕਸਮਲ ਡੌਕੂਮੈਂਟ ਦੀ ਸਮਰੱਥਾ ਦਿੰਦਾ ਹੈ ਜੋ ਸਕੇਮਾ ਦੁਆਰਾ ਨਾ ਸਪੱਸ਼ਟ ਕੀਤੇ ਗਏ ਆਟ੍ਰੀਬਿਊਟ ਰਾਹੀਂ!
<anyAttribute> ਏਲੀਮੈਂਟ
<anyAttribute> ਏਲੀਮੈਂਟ ਸਾਨੂੰ ਐਕਸਟੈਂਡ ਐਕਸਮਲ ਡੌਕੂਮੈਂਟ ਦੀ ਸਮਰੱਥਾ ਦਿੰਦਾ ਹੈ ਜੋ ਸਕੇਮਾ ਦੁਆਰਾ ਨਾ ਸਪੱਸ਼ਟ ਕੀਤੇ ਗਏ ਆਟ੍ਰੀਬਿਊਟ ਰਾਹੀਂ!
ਇਹ ਉਦਾਹਰਣ "family.xsd" ਨਾਮ ਦੇ XML schema ਦਾ ਇੱਕ ਸ਼ੈਕਟ ਹੈ। ਇਹ ਸਾਨੂੰ "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 中声明过的附加元素。