This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Succeeding with AI and have Veljko Krunic on-line!
See this thread for details.
Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

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>
 
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic