XML Attributes with Examples in Hindi
XML Attributes
XML में attributes किसी element के बारे में extra information देने के लिए use किए जाते हैं। ये हमेशा element के start tag में लिखे जाते हैं और element के अंदर मौजूद data को describe या define करने में मदद करते हैं।
XML attributes key-value pair के रूप में लिखे जाते हैं। यहाँ key attribute का नाम होता है और value उस attribute की actual information होती है। उदाहरण के लिए rollno="101" में rollno attribute का नाम है और 101 उसकी value है।
XML Attribute का Basic Syntax
XML में attribute को opening tag के अंदर लिखा जाता है। इसका basic syntax इस प्रकार होता है:
ऊपर दिए गए example में rollno और course attributes हैं। इनकी values क्रमशः 101 और Computer Science हैं।
Attributes कहाँ लिखे जाते हैं?
XML attributes हमेशा opening/start tag के अंदर लिखे जाते हैं। इन्हें closing tag के अंदर नहीं लिखा जाता।
उदाहरण:
यहाँ rollno और course attributes <student> के opening tag में लिखे गए हैं।
Attributes Key-Value Pair होते हैं
XML में attribute का basic format name="value" होता है। Attribute name और value के बीच = sign का use किया जाता है और value को quotes में लिखा जाता है।
- rollno → Attribute name
- 101 → Attribute value
- = → Name और value को connect करता है
उदाहरण:
एक ही element में multiple attributes भी use किए जा सकते हैं। ऊपर rollno, course और status तीन अलग-अलग attributes हैं।
XML Attributes Example
नीचे दिए गए example में multiple students की information दी गई है। प्रत्येक <student> element में rollno और course attributes use किए गए हैं।
Elements और Attributes में Difference
XML में elements और attributes दोनों information represent करने के लिए use किए जाते हैं, लेकिन दोनों की भूमिका अलग होती है। Elements आमतौर पर main या structured data को represent करते हैं, जबकि attributes किसी element के बारे में additional information provide कर सकते हैं।
| Elements | Attributes |
|---|---|
| Main या structured data रखने के लिए use होते हैं | Extra information देने के लिए use होते हैं |
| Opening और closing tags के बीच data रखा जा सकता है | Start tag के अंदर लिखे जाते हैं |
| Complex और larger data के लिए suitable होते हैं | Short और descriptive information के लिए useful होते हैं |
| Child elements रख सकते हैं | Child elements नहीं रखते |
Elements का Example
जब information खुद मुख्य data हो, तो उसे element के रूप में रखना ज्यादा clear हो सकता है:
Attributes का Example
जब information किसी element की extra पहचान या छोटी detail बताती है, तो उसे attribute के रूप में represent किया जा सकता है:
इस example में name और email main data को represent कर रहे हैं, जबकि rollno और course student की additional information के रूप में attributes में दिए गए हैं।
Multiple Attributes का Use
एक XML element में एक से अधिक attributes हो सकते हैं। प्रत्येक attribute को space से अलग किया जाता है।
इस example में एक ही <product> element के अंदर कई attributes use किए गए हैं। ये product की identification और कुछ additional details provide कर रहे हैं, जबकि product का main data child elements में रखा गया है।
Attributes के Important Rules
- Attributes हमेशा element के opening/start tag में लिखे जाते हैं।
- Attribute का basic format
name="value"होता है। - Attribute value को quotes में लिखना चाहिए।
- एक element में multiple attributes हो सकते हैं।
- Attributes को एक-दूसरे से space द्वारा अलग किया जाता है।
- हर attribute name एक element के अंदर unique होना चाहिए।
- Attributes optional होते हैं; हर element में attribute होना जरूरी नहीं है।
- Complex या large data के लिए elements generally ज्यादा suitable होते हैं।
Elements या Attributes का Use कब करें?
XML design करते समय यह decide करना important होता है कि किसी information को element के रूप में रखा जाए या attribute के रूप में। इसका कोई एक universal rule नहीं है, लेकिन सामान्य रूप से main और structured information को elements में रखना ज्यादा clear रहता है, जबकि short descriptive information को attributes में रखा जा सकता है।
उदाहरण के लिए student का name, email और course main data है, इसलिए इन्हें elements में रखा जा सकता है। वहीं rollno या किसी record की छोटी identification information को attribute के रूप में represent किया जा सकता है।
Advantages of XML Attributes
- Elements के बारे में extra information provide करते हैं।
- Data की identification और description को compact बनाते हैं।
- XML document की structure को descriptive बना सकते हैं।
- एक element में multiple attributes use किए जा सकते हैं।
- Simple और short information को represent करने में useful होते हैं।
Conclusion
XML attributes किसी element के बारे में additional information provide करने का एक useful तरीका हैं। ये element के opening tag में name-value pair के रूप में लिखे जाते हैं। Attributes optional होते हैं और एक element में multiple attributes भी use किए जा सकते हैं।
XML में elements और attributes दोनों का अपना अलग purpose है। Main और complex data के लिए elements अधिक suitable हो सकते हैं, जबकि किसी element की छोटी और descriptive information के लिए attributes useful होते हैं। सही तरीके से attributes का use करने से XML document की structure और readability बेहतर हो सकती है।
इस example में <students> root element है। इसके अंदर तीन <student> child elements हैं। प्रत्येक <student> के अंदर <name>, <rollno>, <course> और <email> जैसे nested elements मौजूद हैं।
इस example से XML की hierarchical structure को आसानी से समझा जा सकता है। सबसे ऊपर root element है, उसके नीचे student records हैं और प्रत्येक record के अंदर उससे संबंधित individual data elements हैं।
Parent और Child Elements
XML में elements के बीच parent-child relationship बनती है। जो element किसी दूसरे element के अंदर मौजूद होता है, वह child element कहलाता है। जिस element के अंदर child element मौजूद होता है, वह parent element कहलाता है।
उदाहरण के लिए:
<student>
<name>Rahul Sharma</name>
<course>Computer Science</course>
</student>
यहाँ <student> parent element है और <name> तथा <course> child elements हैं। इस तरह XML elements एक hierarchy बनाते हैं, जिससे complex data को भी organized तरीके से represent किया जा सकता है।
XML Elements की Important बातें
- XML element XML document की basic building block है।
- एक सामान्य element में start tag और end tag होता है।
- Element के अंदर text, nested elements या दोनों हो सकते हैं।
- XML element names case-sensitive होते हैं।
- XML document में एक root element होना चाहिए।
- एक element के अंदर दूसरे elements को nest किया जा सकता है।
- Meaningful element names data को समझना आसान बनाते हैं।
- Empty elements को self-closing syntax से लिखा जा सकता है।
- Elements और attributes दोनों XML data को describe करने में उपयोगी होते हैं।
XML Elements के फायदे
- Structured Data: Data को hierarchical structure में organize किया जा सकता है।
- Readability: Meaningful tags के कारण XML data को पढ़ना आसान होता है।
- Flexibility: आवश्यकता के अनुसार custom elements बनाए जा सकते हैं।
- Data Exchange: अलग-अलग applications के बीच structured data exchange किया जा सकता है।
- Maintainability: Properly organized XML document को समझना और maintain करना आसान होता है।
Conclusion
XML Element XML document का एक fundamental part है। इसके माध्यम से data को meaningful और hierarchical structure में organize किया जाता है। Start tag, end tag, content, nesting, parent-child relationship और root element XML structure को समझने के लिए बहुत important concepts हैं।
जब XML elements को सही तरीके से organize किया जाता है, तो complex information को भी एक structured और readable format में represent किया जा सकता है। इसी वजह से XML का use data exchange, configuration और विभिन्न software systems के बीच information sharing जैसे कामों में किया जाता है।
Request
Leave a Comment
INITIALIZING...
INITIALIZING...
Comments Total: 0 comments