Empty Elements : Well Formed « Introduction « XML Tutorial

Home
XML Tutorial
1.Introduction
2.Namespace
3.XML Schema
4.XPath
5.XSLT stylesheet
XML Tutorial » Introduction » Well Formed 
1.3.6.Empty Elements
Sometimes an element has no PCDATA. 


<name nickname='007'> 
    <first>James</first> 
    <middle></middle <!--James does not have middle name -->  > 
    <last>Bond</last> 
</name> 

You can write this element using a self-closing tag: 

<middle/> 

The / and > always have to be together

<middle /> or this  <middle/> 

but not like this <middle/ > or this <middle / > 

Empty elements are used for elements with no PCDATA but attributes. 

<name first="Bond" 
      middle="James" 
      last="Last"/>
1.3.Well Formed
1.3.1.XML documents must adhere to certain rules to be well formed.
1.3.2.XML Naming Conventions
1.3.3.Case Sensitivity
1.3.4.Writing Non-Empty Elements
1.3.5.Nesting Elements
1.3.6.Empty Elements
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.