Menu

Related Topics

HTML CSS JavaScript PHP Node.js React.js C C++ Go Rust Swift Python Java Excel MS Word PowerPoint
Search

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 इस प्रकार होता है:

XML
Code copied!

ऊपर दिए गए example में rollno और course attributes हैं। इनकी values क्रमशः 101 और Computer Science हैं।

Attributes कहाँ लिखे जाते हैं?

XML attributes हमेशा opening/start tag के अंदर लिखे जाते हैं। इन्हें closing tag के अंदर नहीं लिखा जाता।

उदाहरण:

XML
Code copied!

यहाँ rollno और course attributes <student> के opening tag में लिखे गए हैं।

Attributes Key-Value Pair होते हैं

XML में attribute का basic format name="value" होता है। Attribute name और value के बीच = sign का use किया जाता है और value को quotes में लिखा जाता है।

उदाहरण:

XML
Code copied!

एक ही element में multiple attributes भी use किए जा सकते हैं। ऊपर rollno, course और status तीन अलग-अलग attributes हैं।

XML Attributes Example

नीचे दिए गए example में multiple students की information दी गई है। प्रत्येक <student> element में rollno और course attributes use किए गए हैं।

XML
Code copied!

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 हो सकता है:

XML
Code copied!
Attributes का Example

जब information किसी element की extra पहचान या छोटी detail बताती है, तो उसे attribute के रूप में represent किया जा सकता है:

XML
Code copied!

इस example में name और email main data को represent कर रहे हैं, जबकि rollno और course student की additional information के रूप में attributes में दिए गए हैं।

Multiple Attributes का Use

एक XML element में एक से अधिक attributes हो सकते हैं। प्रत्येक attribute को space से अलग किया जाता है।

XML
Code copied!

इस example में एक ही <product> element के अंदर कई attributes use किए गए हैं। ये product की identification और कुछ additional details provide कर रहे हैं, जबकि product का main data child elements में रखा गया है।

Attributes के Important Rules

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

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 बेहतर हो सकती है।

XML
Code copied!

इस 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 Elements के फायदे

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 जैसे कामों में किया जाता है।


Code copied!

Page Views
0
Visit ID
Not tracked yet
Visit Time
-
Time on Page
0 seconds

Request


Leave a Comment


INITIALIZING...


INITIALIZING...


Quizzes in Hindi

GK Online Quiz in Hindi 10 pages
HTML Online Quiz in Hindi 10 pages
CSS Online Quiz in Hindi 10 pages
JavaScript Online Quiz in Hindi 10 pages
CCC Online Quiz in Hindi 10 pages
History Online Quiz in Hindi 10 pages



Comments Total: 0 comments

📰 Latest Articles

Total: 0 Articles

Featured Products

0 Products 0 Loaded 0 Remaining

All Products Loaded!

You've reached the end of our collection.

Contact Us Form