Hi all,

  I'm using CF5 and msxml for the following. I'm looking for advice on
improving my method. My current method works fine, but it seems that there
should be a better way.

Here's the situation: I'll be looping through a directory of about 20 xml
documents at any one time, all conforming to one DTD. However, the XML
documents will only
contain some of the info that the DTD allows for, and this isn't
really predictable. They're guaranteed to have about 40% of the DTD's
elements. The other elements may or may not be present. Of those that
may or may not be present, only 2 or 3 will be inserted into the
database (NULL optional fields).

  Currently, I load the XML into memory (DOM), then set a variable for
each element I need to get, something like this:

  EditorialNumber =
myBaseTagName.selectSingleNode("article-info/editorial-number");
  FirstAuthor = myBaseTagName.selectSingleNode("author-group/first-author");

So I may have 20 variables being set. I then access these variables
whenever I need them (for display or for database inserts. For
example:

insert into JPETArticles(EditorialNumber, FirstAuthor)
values('EditorialNumber.text', 'FirstAuthor.text');

This code works fine and is pretty fast. But here are the problems:

1) in the code above, if the first-author element is not present or is
empty, then any attempt to access the variable throws an error.
Obviously, I'd rather not have a test for existence for every element
that may or may not be present.

2) It's not very extensible. Let's say my XML documents contain 50
elements, and we're currently only parsing 25 of them, and then my
boss says "OK, we're going to start using the data from 5 more of the
elements", then I have to change my code to add more
"selectSingleNode().." lines.

So, if you were in my situation, how would you approach these
problems?

I appreciate any advice.

Marc


-----------------------+
cf-xml mailing list
list: [EMAIL PROTECTED]
admin: [EMAIL PROTECTED]
home: http://torchbox.com/xml

Reply via email to