XML declaration and rules of declaration

declaration ના rules થોડા અને rigid છે: lowercase <?xml, absolutely first (કોઈ space નહીં, કોઈ comment નહીં, ઉપર કોઈ blank line નહીં), version compulsory, encoding અને standalone optional અને તે order માં, values quoted.

9 min read · 9 cards · 2 checks

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


Theory

ગરબા નાઈટ garbage બને છે

committee event names bilingual માંગે છે: <name>ગરબા નાઈટ</name> events.xml માં join થાય છે. તમારી machine પર, fine. vendor ના system પર, name question marks અને boxes તરીકે renders થાય છે.

file એ ક્યારેય કહ્યું નહોતું કે તે કયું character encoding use કરે છે, તેથી vendor ના parser એ guess કર્યું, wrongly.

cure એ એક line છે જે તમે lesson 1 થી autopilot પર type કર્યું છે. today તે line ને closely read કરવામાં આવે છે, કારણ કે તેના rules rigid છે અને exams દરેક one ને check કરે છે.

Theory

declaration, member by member

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

  • version: COMPULSORY, હંમેશા first; practice માં 1.0
  • encoding: optional; character set ને names કરે છે. UTF-8 (default) દરેક script ને cover કરે છે જે events.xml meet થશે, ગરબા included. તેને declaring કરવું vendor ના guesswork ને remove કરે છે
  • standalone: optional; yes એટલે document ને સમજવા માટે કોઈ external DTD file ની જરૂર નથી; no એટલે તે હોઈ શકે

Delimiters: opens <?xml, closes ?>. તે instruction છે, element નહીં: કોઈ closing tag exist નથી કરતું, અને તે ક્યારેય root તરીકે count નથી થતું.

Theory

declaration ના rules

પાંચ rules, બધા enforced:

  • Position: જો present હોય, absolutely first: કોઈ blank line નહીં, કોઈ space નહીં, કોઈ comment નહીં, તેની ઉપર અથવા before એક પણ character નહીં
  • Case: lowercase <?xml; <?XML અને <?Xml illegal છે
  • version mandatory છે અને attributes માં first stands કરે છે
  • Order fixed છે: version, પછી encoding, પછી standalone; rearranging એ error છે
  • Values quoted છે, single અથવા double, દરેક XML attribute જેમ

અને earlier lessons નો meta-rule: declaration itself OPTIONAL છે. કોઈ declaration legal છે; misplaced અથવા misspelt એક નથી.

Practical

એક valid, ચાર invalid: શા માટે spot કરો

<!-- VALID -->
<?xml version="1.0" encoding="UTF-8"?>

<!-- INVALID: uppercase XML -->
<?XML version="1.0"?>

<!-- INVALID: version missing -->
<?xml encoding="UTF-8"?>

<!-- INVALID: order swapped -->
<?xml encoding="UTF-8" version="1.0"?>

<!-- INVALID: unquoted value -->
<?xml version=1.0?>

Quiz

file એક blank line થી શરૂ થાય છે, પછી line 2 પર <?xml version="1.0"?> છે, પછી perfect root element છે. parser શું કહે છે?

  1. Fine: declaration પહેલાં whitespace ને ignored કરવામાં આવે છે
  2. Error: declaration એ absolute first thing હોવું જોઈએ, અને blank line તેને breaks કરે છે
  3. Fine, પણ declaration ને comment તરીકે treated કરવામાં આવે છે
  4. Error: version 1.0 outdated છે
Show the answer

Error: declaration એ absolute first thing હોવું જોઈએ, અને blank line તેને breaks કરે છે

position rule એ absolute છે: not even invisible whitespace declaration ને precede કરી શકે છે, તેથી એક innocent blank line document ને invalidate કરે છે: આ unit નો single most common hand-editing bug, કારણ કે editors silently leading lines add કરે છે. Option A HTML ની tolerance ને language માં import કરે છે જેની પાસે none છે. Option C downgrade mercy ને invent કરે છે જે parsers perform નથી કરતા. Option D noise છે: 1.0 practice માં standard version રહે છે. Fix: blank line ને delete કરો; declaration file ના first byte ને touch કરે છે.

Think first

કઈ line એ ગરબા નાઈટ ને saved કર્યું?

precisely explain કરો કે કેવી રીતે encoding="UTF-8" vendor ના question-mark garbage ને fixes કરે છે, tap કરતા પહેલાં. vendor નો parser તેના વગર શું કરી રહ્યો હતો?

Show the answer

file માં text એ ફક્ત bytes છે; encoding એ codebook છે જે bytes ને characters માં map back કરે છે. Gujarati letters UTF-8 માં દરેક multiple bytes પર span કરે છે, અને vendor નો parser, કંઈ told નહોતું, single-byte codebook ને guess કર્યું: દરેક Gujarati byte ને wrong અથવા unprintable Latin-era character તરીકે decoded: hence boxes અને question marks. encoding="UTF-8" ને declaring કરવું દરેક consumer ને right codebook up front hands કરે છે. Habit: કોઈ પણ XML જે ક્યારેય non-English text ને carry કરી શકે તે UTF-8 ને explicitly declare કરે છે, even though તે default છે, કારણ કે day જે તે travels કરે છે તે day defaults differ થાય છે.

Watch out

ત્રણ declaration slips

invisible blank line: quiz bug; જ્યારે valid-looking declaration errors કરે ત્યારે file ના very first character ને check કરો.

તેને element તરીકે Treating કરવું: તેને "close" કરવા માટે </xml> લખવું, અથવા તેને second root તરીકે count કરવું: તે instruction છે; ?> એ તેનું entire ending છે.

Casual attribute order: encoding before version કોઈ parser માં compile નથી થતું; order version, encoding, standalone એ grammar છે, style નહીં.

Theory

Unit 1 closes: events.xml complete છે

stock લો: FestConnect નું data એક well-formed events.xml માં lives કરે છે: declared UTF-8, એક root, quoted attributes, matched cases, clean nesting, sections જે તમે name કરી શકો છો. તમે XML ને write કરી શકો છો અને, just as valuably, stranger ને DEBUG કરી શકો છો. Unit 2 seats entirely changes કરે છે: data files થી live page સુધી, જ્યાં jQuery FestConnect ના schedule ને fold, fade અને react કરાવે છે. XML Unit 4 માં returns થાય છે, જ્યારે AJAX તેને reload વગર fetch કરે છે.

Summary

Key takeaways

  • Form: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>, instruction, element નહીં.
  • જો present હોય, તો તે file નું absolute first thing છે: ઉપર કોઈ space, line અથવા comment નહીં.
  • ફક્ત lowercase <?xml; version compulsory અને first છે; order fixed: version, encoding, standalone; values quoted.
  • encoding byte-to-character codebook ને names કરે છે; UTF-8 Gujarati અને Hindi ને safely cover કરે છે.
  • standalone="yes" એટલે કોઈ external DTD needed નથી.
  • declaration optional છે; wrong એક fatal છે, missing એક fine છે.
  • Memory hook: first byte, lowercase, version-encoding-standalone.

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 Introduction of XML

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

XML declaration and rules of declaration · Web Designing-2 (option A) · Gri-Learn