XSD ਕਿਵੇਂ ਇਸਤੇਮਾਲ ਕਰਨਾ ਹੈ?
- ਪਿਛਲਾ ਪੰਨਾ XSD ਕਿਉਂ ਇਸਤੇਮਾਲ ਕਰਨਾ ਹੈ?
- ਅਗਲਾ ਪੰਨਾ XSD <schema>
XML ਦਸਤਾਵੇਜ਼ DTD ਜਾਂ XML Schema ਨੂੰ ਹਵਾਲਾ ਦੇ ਸਕਦੇ ਹਨ。
ਇੱਕ ਸਰਲ XML ਦਸਤਾਵੇਜ਼:
ਇਹ "note.xml" ਨਾਮ ਦਾ XML ਦਸਤਾਵੇਜ਼ ਦੇਖੋ:
<?xml version="1.0"?> <note> <to>George</to> <from>John</from> <heading>Reminder</heading> <body>Don't forget the meeting!</body> </note>
DTD ਫਾਈਲ
ਇਹ ਉਦਾਹਰਣ "note.dtd" ਨਾਮ ਦੇ DTD ਫਾਈਲ ਹੈ ਜੋ ਉੱਪਰ ਦੇ XML ਦਸਤਾਵੇਜ਼ ਦੇ ਤੱਤਾਂ ਨੂੰ ਪਰਿਭਾਸ਼ਿਤ ਕਰਦਾ ਹੈ:
!ELEMENT note (to, from, heading, body) <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)>
ਪਹਿਲੇ ਹਰਫ਼ ਵਿੱਚ note ਇਲਾਕੇ ਦੇ ਚਾਰ ਉਪ ਇਲਾਕੇ ਹਨ: "to, from, heading, body"。
ਦੂਜੇ 5 ਹਰਫ਼ ਵਿੱਚ to, from, heading, body ਇਲਾਕੇ ਦੀ ਕਿਸਮ "#PCDATA" ਹੈ。
XML Schema
ਇਹ ਉਦਾਹਰਣ "note.xsd" ਨਾਮ ਵਾਲੀ XML Schema ਫਾਈਲ ਹੈ ਜੋ ਉੱਪਰ ਦੇ XML ਦਸਤਾਵੇਜ਼ ਦੇ ਇਲਾਕੇ ਨੂੰ ਪਰਿਭਾਸ਼ਿਤ ਕਰਦੀ ਹੈ:
<?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.codew3c.com" xmlns="http://www.codew3c.com" elementFormDefault="qualified"> <xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:string"/> <xs:element name="body" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
note ਇੱਕ ਮਿਸ਼ਰਿਤ ਤਰੀਕਾ ਹੈ ਕਿਉਂਕਿ ਇਹ ਹੋਰ ਉਪ ਇਲਾਕੇ ਦੇ ਨਾਲ ਹੈ। ਹੋਰ ਇਲਾਕੇ (to, from, heading, body) ਸਰਲ ਤਰੀਕਾ ਹਨ ਕਿਉਂਕਿ ਇਹ ਹੋਰ ਇਲਾਕੇ ਨਹੀਂ ਹਨ। ਤੁਸੀਂ ਨਿਚੇ ਦੇ ਅਧਿਆਏ ਵਿੱਚ ਕੰਪਲੈਕਸ ਤਰੀਕਾ ਅਤੇ ਸਰਲ ਤਰੀਕਾ ਬਾਰੇ ਅਧਿਕ ਜਾਣੂ ਹੋ ਜਾਓਗੇ。
DTD ਦੀ ਰਾਹ ਦਿਖਾਉਣਾ
ਇਹ ਫਾਈਲ DTD ਦੀ ਰਾਹ ਦਿਖਾਉਂਦੀ ਹੈ:
<?xml version="1.0"?> <!DOCTYPE note SYSTEM "http://www.codew3c.com/dtd/note.dtd"> <note> <to>George</to> <from>John</from> <heading>Reminder</heading> <body>Don't forget the meeting!</body> </note>
XML Schema ਦੀ ਰਾਹ ਦਿਖਾਉਣਾ
ਇਹ ਫਾਈਲ XML Schema ਦੀ ਰਾਹ ਦਿਖਾਉਂਦੀ ਹੈ:
<?xml version="1.0"?> <note> xmlns="http://www.codew3c.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.codew3c.com note.xsd"> <to>George</to> <from>John</from> <heading>Reminder</heading> <body>Don't forget the meeting!</body> </note>
- ਪਿਛਲਾ ਪੰਨਾ XSD ਕਿਉਂ ਇਸਤੇਮਾਲ ਕਰਨਾ ਹੈ?
- ਅਗਲਾ ਪੰਨਾ XSD <schema>