如何使用 XSD?

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)>

నోట్ ఎలమెంట్ అనేది నాలుగు ఉపఎలమెంట్లు కలిగి ఉంటుంది: "to, from, heading, body".

2-5 వరుసలు to, from, heading, body అంశాల రకాన్ని "#PCDATA" గా నిర్వచిస్తాయి.

ఎక్సిఎమ్ఎల్ షేమా

ఈ ఉదాహరణ ఒక "note.xsd" పేరుతో ఉన్న XML స్కీమా ఫైలు, ఇది ముందుగా పేర్కొన్న 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 స్కీమాకు సూచనలు

ఈ ఫైలు XML స్కీమాకు సూచనలను కలిగి ఉంది:

<?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>