XML Elements - what is xml element - use of xml element

what is xml element :- xml elements are the basic building blocks of xml and all documents will have at least one.xml elements can be extended to carry more information.

the xml document all elements are defined in one of two ways.

<tag_name> tag-content </tag_name>

self-closing element :- <tag_name />

xml element can contain :

  • text
  • attribute
  • other elements

a xml file look like -

                 <? xml version= "1.0" ?>
                 
                       <information>_________________________root element
                         
                              <developer category = "web" >
                                 

opening element______<name> sandeep </name>_________closing element
                                              |
                                              |
                                              |
                                            element content                             
                                 
                                 
                                   <age>  25  </age>
                                   
                                   <town> dinwa jatan </town>
                                   
                                   <company> microsoft </company>
                                   
                              </developer>
                             
                             
                              <developer category = "application" >
                                 
                                   <name> vinod </name>
                                   
                                   <age>  25  </age>
                                   
                                   <town> bangalore </town>
                                   
                                   <company> microsoft </company>
                                   
                              </developer>
                              
                           
                     </information>           
            

xml element naming rules

  • element names must begin with a letter or an underscore( _ ).
  • names can't contain spaces.
  • names are case-sensitive, so the start and end tags must match exactly.
  • names can't contain the colon(:) character.
  • there can't be a space after the opening < character, the name of the element must come immediately after it.however there can be space before the closing > character if you desire.

legal and illegal elements.

xml tagsreason
<firstname></firstname>correct
<first name></first name>incorrect, because names cannot contain white spaces.
<number3></number3>correct
<3number></3number>incorrect, because names cannot begins with a digit.
<second_name></second_name>correct, underscore allowed.
<-name></-name>incorrect, because hyphen is not allowed as the first character.
<sandeep></sandeep>correct.
<sandeep></sandeep>incorrect,start and end tag must match case-sensitive.
<!name></!name>incorrect, operators not allowed(# $ % * ^ ~ = + !).