Introduction to XML in Flash
by senocular
Evaluation: XML And Your Family Tree
I've been ranting on an on throughout
that XML seems fit for a family tree. Parents,
children, siblings - XML just seems so very
family oriented. But is that really the case?
Lets take a closer look at how elements in an
XML hierarchy are arranged and whether or not
they make presenting a family tree easy.
Way back when, the file-folder analogy was
used to help describe the structure of XML.
You have folders (elements) and in those folders
you have files or more folders (elements and
other child nodes). Any single folder can have
any number of files or folders and any of those
folders within a folder can have their own similar
collection and so on. A file or folder, however,
only exists in a single folder at any given
time. You get a relation that looks like this:
[
general structure of xml ]
Because everyone can relate to their family
and know who's who (who's a parent and who's
a child), keywords used to describe similar
relations are used to make using XML more comprehensible
- child nodes, parent node... siblings, etc.
However, if you think about it, they aren't
quite exactly the same. There's one key difference
in the real family structure when compared to
that of XML. That difference is having two parents.
Look at the following. It represents a portion
of the family structure of a single person (subject)
[
structure of a family tree ]
Here, the subject belongs to two parents, a
mother and a father. The children belong not
only to the subject, but also to the subject's
spouse. So the children, too, have more than
one parent. Like with files and folders, this
just isn't possible with XML (that's right,
XML does not support multiple inheritance).
This doesn't, however, make an XML version of
a family tree impossible. It just makes it so
that an XML representation will not structurally
match the content it contains. And there's nothing
wrong with that. It's perfectly fine but it
also means that interpreting that information
will might take a little more effort.
An example would be... wouldn't you know it,
FTML.
Yup, Family Tree Markup Language - XML for family
trees (FTML is technically based off of SGML
like HTML and XML). FTML uses id attributes
to manage and relate people to other people
as they are linearly listed within a FTML document.
Take a look at this quick example:
- <?xml version='1.0'?>
- <!DOCTYPE ftml SYSTEM
"ftml.dtd">
- <ftml>
- <people>
- <person
id="Granddad"
sex="male"
surname="Example"
forenames="Granddad">
- <born
date="1915"
/>
- <died
date="1998"
/>
- </person>
- <person
id="Grandma"
sex="female"
surname="Jones"
forenames="Granny"
/>
-
- <person
id="Dad"
sex="male"
surname="Example"
forenames="Daddy">
- <born
date="1940"
/>
- <mother
id="Grandma"
/>
- <father
id="Granddad"
/>
- </person>
- <person
id="Mom"
sex="female"
surname="Smith"
forenames="Mommy"
/>
- <person
id="Uncle"
sex="male"
surname="Example"
forenames="Uncle"
/>
- <person
id="Aunt"
sex="female"
surname="Trotter"
forenames="Aunt"
/>
-
- <person
id="Me"
sex="male"
surname="Example"
forenames="Me">
- <born
date="1973"
/>
- <mother
id="Mom"
/>
- <father
id="Dad"
/>
- </person>
- <person
id="Brother"
sex="male"
surname="Example"
forenames="Brother">
- <born
date="1971"
/>
- <mother
id="Mom"
/>
- <father
id="Dad"
/>
- </person>
- </people>
- <marriages>
- <marriage
husband="Dad"
wife="Mom"
date="1964"
/>
- <marriage
husband="Uncle"
wife="Aunt"
/>
- </marriages>
- </ftml>
All people within this family structure here
are listed linearly in the people element. Each
person is given an id which is then referenced
in two places: 1) in the person definition where
a mother and/or father is specified and 2) in
the marriages section where a husband and wife
are connected by id (some versions of xml-based
family trees keep marriage relations within
the person tag under wife or husband).
So, the best use of the XML hierarchy within
this document is just maintaining content concerning
a single person (and the collection of people).
Actual relations are all handled through ids.
So despite my hopes in creating an example based
on a family tree, given the type of XML design
needed above, that's not something we're about
to tackle here. Lets continue with another,
simpler example. For your own XML projects,
however, you may need to consider a setup something
similar to FTML. Something to keep in mind.
|