XML document: Document Prolog Section, Document element section

एक XML document के दो parts होते हैं: top पर prolog section (declaration, plus optional comments, processing instructions, और एक DTD/schema) और document element section (अकेला root element और इसके अंदर nested सब कुछ), और prolog हमेशा root से पहले आता है।

8 min read · 10 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

एक file दो हिस्सों में

एक पूरी FestConnect XML file फिर से देखिए। Top पर file के बारे में एक line होती है (<?xml ...?>), शायद एक comment। इसके नीचे असली data बैठा है, एक root element में wrapped।

XML formally इन दो हिस्सों को नाम देता है: prolog section (header material) और document element section (data)। कौन सा कौन है यह जानना, और prolog पहले आता है यह, एक छोटा पर reliable exam question है और साफ़ करता है हर XML file कैसे laid out है।

Theory

एक letter का letterhead और इसका body

एक formal letter में top पर एक letterhead होता है: date, reference number, शायद paper के बारे में एक note। फिर आता है body, असली message। Letterhead describe करता है और पहले आता है; body content ले जाता है। एक XML document वैसा ही है: prolog letterhead है (declaration, comments, schema), और document element body है (root और इसका data)।

Theory

दो sections

  • Prolog section (optional, top पर): XML declaration (<?xml version="1.0" encoding="UTF-8"?>), plus optional comments, processing instructions, और एक DTD/schema reference (DOCTYPE)। यह document describe करता है।
  • Document element section (body): अकेला root element और इसके सभी nested children और content। यह असली data है।

Order matter करता है: prolog पहले आता है; फिर exactly एक root। अगर declaration मौजूद है, यह बिल्कुल पहली line होनी चाहिए।

Practical

Prolog और body, labelled

<!-- ===== PROLOG SECTION ===== -->
<?xml version="1.0" encoding="UTF-8"?>
<!-- a fest registration record -->

<!-- ===== DOCUMENT ELEMENT SECTION ===== -->
<registration>
  <name>Aditi Shah</name>
  <year>2</year>
  <event>Robotics</event>
</registration>

At a glance

एक नज़र में दो sections

Sectionक्या रखता हैRequired?
Prologdeclaration, comments, DTD/schemaoptional
Document elementअकेला root + इसका datarequired

Think first

कौन सा part data है?

Snippet में, कौन सा section असली registration values रखता है, और कौन सा सिर्फ़ file describe करता है? और अगर आप पूरा prolog delete कर दें, क्या file फिर भी अपना data रखेगी?

Show the answer

Document element section (<registration>...</registration>) असली data रखता है: नाम, year, और event। Prolog (<?xml ...?> line और comment) सिर्फ़ file describe करता है, यह कोई registration data नहीं ले जाता। अगर आप पूरा prolog delete कर दें, file फिर भी अपना data रखेगी और फिर भी well-formed हो सकती है, क्योंकि prolog optional है। एक चीज़ जो आप drop नहीं कर सकते वह अकेला root element है, वह required body है।

Quiz

एक XML document में prolog कहाँ दिखता है, और अगर एक XML declaration मौजूद है तो क्या सच होना ज़रूरी है?

  1. Prolog top पर है, root से पहले; declaration बिल्कुल पहली line होनी चाहिए
  2. Prolog bottom पर है, root element के बाद
  3. Prolog root element को पूरी तरह replace कर देता है
  4. Declaration root के अंदर कहीं भी दिख सकती है
Show the answer

Prolog top पर है, root से पहले; declaration बिल्कुल पहली line होनी चाहिए

Prolog file के top पर header section है, document element (root) से पहले, और अगर एक XML declaration शामिल है यह बिल्कुल पहली line होनी चाहिए, इससे पहले कुछ नहीं (A)। Prolog कभी bottom पर नहीं है (B), और यह root को replace नहीं करता (C), जो required data body है। Declaration root के अंदर float नहीं कर सकती (D)। Prolog पहले, फिर एक root।

Watch out

Document-structure traps

1. Declaration से पहले content: <?xml ...?> से पहले एक blank line या comment भी इसे invalid बना देता है। Declaration, अगर मौजूद है, line एक है।

2. Prolog को 'data' कहना: prolog सिर्फ़ file describe करता है; document element data रखता है।

3. Body में दो roots: document element section अभी भी पिछले lesson के one-root rule को मानता है।

Theory

अगला: declaration line पास से

Prolog का सबसे ज़रूरी piece XML declaration है। Final XML lesson इसमें zoom करता है: version और encoding का मतलब क्या है, कौन से parts required हैं, इसके attributes का order, और यह lowercase और पहले क्यों होना चाहिए। फिर आप Unit 4 में असली Android widgets के साथ FestConnect की screen बनाने वापस जाते हैं।

Summary

Key takeaways

  • एक XML document के दो sections हैं: prolog (top) और document element (body)।
  • Prolog (optional): XML declaration, comments, processing instructions, और कोई DTD/schema।
  • Document element (required): अकेला root element और इसका सारा nested data।
  • Prolog पहले आता है; अगर एक declaration मौजूद है यह बिल्कुल पहली line होनी चाहिए, इससे पहले कुछ नहीं।
  • Prolog delete करना फिर भी एक valid file छोड़ सकता है; root delete करना नहीं।
  • Memory hook: एक letter का letterhead (prolog) और इसका body (document element)।

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from XML (Extensible Markup Language)

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati

XML document: Document Prolog Section, Document element section · Mobile Application Development - 1 (option B) · Gri-Learn