Re: [xml] "Proper" way to use XML (not library specific)



Will Sappington wrote:

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?

Many thanks in advance for any thoughts you might care to share.


I don't have anything technical to add to this, but I am very interested in this as well. My way of thinking is much like yours; I've written a handful of functions that pull attributes and values out of the DOM and use those; things like getElementValue and getAttribute.

A consultant we hired used your manager's method, converting the DOM to an array and then using the array elements.

I find my method easier to understand and maintain, but harder to program initially. The consultant's method is easy to program - he just has a single DOMtoArray function - but then has to test for the existence of each element separately, so his code ends up being full of if(isset(array['something'])) blocks.

Both methods work well from a performance standpoint. I think I will get some performance improvement by selecting a single method. I suspect that for large amounts of data handling the array method is quicker, but for pulling a small number of values out of the XML file my method is quicker. I haven't profiled this yet, though.

The XPath method is also more flexible, as it allows you to select a particular branch of the tree easily. I've broken up my single enormous config file ( 300K! talk about feature creep....) into a sequence of smaller files. Using XPath allowed me to do this very easily, whereas the array stuff is more-or-less hard-coded and harder to maintain.

--Yan



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]