XML for the absolute beginner
Modeling information structure in XML
So far, we've looked at XML as a way of representing data as
human-readable documents, and we've spent some time discussing
formatting. But XML's real power is in its ability to represent
information structure -- how various pieces of information relate to
one another -- in much the same way a database might.
Structured documents of the type we've been looking at have the
property that all of their elements nest inside one another, as in
Listing 5 above. Instead of looking at a document as a file, though,
consider what happens if we look at the structure of the tags as a
tree:
|
The figure above shows the recipe as a tree of document tags. The child
nodes of a document nest within the parent node. What if there were a
way to automagically convert an XML document into a tree of
objects in a programming language -- like, oh, say, Java
maybe? And what if these objects all had properties that could be set
and retrieved -- such as the list of each element's children, the text
each object contained, and so on. Wouldn't that be interesting?
The Document Object Model (DOM) Level 1 Recommendation (see
href="#resources">Resources), created by a W3C committee, describes
a set of language-neutral interfaces capable of representing any
well-formed XML or HTML document.
With the DOM, HTML and XML documents can be manipulated as objects,
instead of just as streams of text. In fact, from the DOM point of
view, the document is the object tree, and the XML, HTML, or
what have you is simply a persistent representation of that tree.
The availability of the DOM makes it much simpler to read and write
structured document files, since standard HTML and XML parsers are
written to produce DOM trees. If these objects have GUI
representations, it's easy to see how to create an application that
reads structured document files (XML or HTML), lets the user edit the
structure visually, and then save it in its original format. Programs
that interface with existing Web sites become much easier to write,
because once the document is parsed, you're working with objects native
to your programming language.
One of the earliest popular uses for the Document Object Model is
Dynamic HTML, where client-side scripts manipulate and display (and
redisplay) an HTML document in response to user actions. Dynamic HTML
manipulates the client-side document in terms of the scripting
language's binding to the DOM structure of the document being
displayed.
Sign up for ITworld's Daily newsletter
Follow ITworld on Twitter @IT_world
Esther Schindler
If the comments are ugly, the code is ugly
claird
SVG a graphics format for 21st century
pasmith
Take Chrome OS for a test spin
Sandra Henry-Stocker
Solaris Tip: Have Your Files Changed Since Installation?
jfruh
Android fragments vs. the iPhone monolith
mikelgan
What Gizmodo missed about the Pro WX Wireless USB disk drive
Sidekick: The Good News & the Bad News
Either way you look at it Microsoft Data Center management did not follow standards or best practices in this failure. In which case it makes me wonder more about the outsourcing of corporate data much less personal data.
- mburton325
Join the conversation here
Quick, practical advice for IT pros. Made fresh daily.
Want to cash in on your IT savvy? Send your tip to tips@itworld.com. If we post it, we'll send you a $25 Amazon e-gift card.














