On Wed, 2007-02-14 at 11:58 -0500, Will Sappington wrote:
> The company I work for is standardizing on XML as the means for
> representing various types of data, our configuration files being one
> of them.  We currently use what we call an application profile, just a
> hierarchical structure of name/value pairs, organized in an
> application/section/item hierarchy.  The functional interface to the
> profile is 1) open(), which opens the file and loads it into memory,
> 2) execute one or more getItem()’s to pull out configuration items
> specified by application-name/section-name/item-name, and 3) close()
> the profile.

> I’m new to XML, but based on a recommendation and my own analysis
> after the fact, XPath seemed a reasonable way to replicate this
> functionality in XML because it allows you to directly access specific
> elements.  I’ve had some trouble implementing this, mostly due to a
> lack of understanding of the library that was chosen (Xalan/Xerces).
> In response to my troubles, my manager is saying that the problem is
> with how I’m trying to use XML, not with the library.  He says XPath
> is not appropriate for this, that I should “marshal” the entire XML
> file into a different form, toss the DOM, and operate on the
> transformed data.  I’ll put his email to me, edited for brevity,
> below.  But my question is, if XPath isn’t appropriate for this, then
> what is it appropriate for?  From the perspective of a configuration
> utility, it certainly seems to be reasonable, if not obvious for the
> interface to be such that the user can read specific configuration
> items from the file in whatever order is desired, and XPath appears to
> be designed to do specifically that with XML data.  So why would it
> not be an appropriate tool to use for migrating our existing
> name/value pairs (.ini files) to XML?

Bottom line, you can do it either way. Irrespective of whether you
marshal the data into your own data structure or reference it directly
in the DOM tree you still will as a first step need to locate the data
in the XML file, XPath is a very convenient way to do this. But it does
require you know what to query a priori, a lot of times that's not the
case (see comment about SAX below)

As to whether the queries in your API reference the DOM directly via
XPath, or a private data structure you built from the DOM is an
implementation choice dictated by your particular circumstances.

However, do consider the option of using SAX, not DOM for your purpose.
SAX is well suited to marshaling config file entries. The idea is your
SAX callbacks build the marshaled data structure as the file is parsed.
There is a tremendous advantage to this because the marshaled data
"builds itself".

It's not unusual to discover a marshaled data structure is easier to
work with once built, especially if any of the data needs to be
normalized, validated, or cross referenced in any manner.
-- 
John Dennis <[EMAIL PROTECTED]>

_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
[email protected]
http://mail.gnome.org/mailman/listinfo/xml

Reply via email to