XML Descendant

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

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.

XML Tree:

Bonus Question: What are the descendants of lemonade?

Answerprice and amount.