• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can Empty Element contain child nodes?

 
ZEESHAN AZIZ
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.
 
Shoba Ramachandran
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
 
Avinash Mulye
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.
 
Luciano Queiroz
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!
 
Jayadev Pulaparty
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>
 
Ronak Patel
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>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic