• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Can Empty Element contain child nodes?

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Empty element is not allowed to have any text. I was wondering whether empty element can contain child nodes.
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Empty elements are allowed to have text and attribtues and not allowed to have any child element nodes.
Shoba
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we realy have text as apart of an empty element ? Consider the following example -
<abc> Hello
<pqr value="10" /> How are you ?
</abc>
In the above example I believe <pqr> is an empty element. The text nodes are
1)Hello
2)How are you ?
Which element do they belong to - <abc> or <pqr> ?
I am not sure !
Avinash.
 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An empty element cannot contain characters data nor child elements.
An empty element can only contain attributes!
 
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Text is treated as a child node and hence cannot be part of an empty element; It can have any number of PIs though as shown here -
<!DOCTYPE root SYSTEM "sample.dtd"[
<!ELEMENT root ANY>
<!ATTLIST root attr1 CDATA #REQUIRED>
<!ELEMENT jayadev EMPTY>
<!ATTLIST jayadev dev CDATA "pulaparty">
]>
<root attr1="att1">
<jayadev dev="jpulapar"><?PIData xxxx=yyyy ?></jayadev>
</root>
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An empty element can contain only attributes.
1)Valid empty element
<abc/>
<abc att="pqr" />
2)Not Valid empty element
<abc> xyz </abc>
<abc>
<pqr/>
</abc>
<abc>
xyz
<pqr/>
</abc>
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!