XML Tree - Descendant
Any children that you have are your descendants. Any children that your children have are also your descendants. It doesn't matter how far down the family tree these children are; they will always be your descendants.
A descendant relationship is similar in XML. Element A is the descendant of element B if the following is true:
- Element A is contained within element B.
Is an Element a Descendant?
If you are determining if one element is the descendant of another element, you will need to find the opening and closing tags of both elements to determine the relationship.
We have highlighted inventory and lemonade in our lemonade.xml document; try to determine determine which element is the descendant.
XML Code, lemonade.xml:
lemonade is the descendant of inventory. This situation was a little tricky because lemonade is contained within another element, drink. However, it doesn't matter how far down the XML Tree an element is. If it's contained by another element, then it is that element's descendant.
Here is a graphical representation of the relationship between inventory and lemonade. You can clearly see that lemonade is the descendant.
Bonus Question: What are the descendants of lemonade?
Answer: price and amount.
Download Tizag.com's XML Book
If you would rather download the PDF of this tutorial, check out our
XML eBook from the Tizag.com store.
Found Something Wrong in this Lesson?
Report a Bug or Comment on This Lesson - Your input is what keeps Tizag improving with time!