How Do I search an XML File?

  • Thread starter Thread starter Gary
  • Start date Start date
G

Gary

I have an attribute-centric xml file which can't be imported directly into
Access. In addition have have look into KB article#285329 and I don't know
how to change the xsl stylesheet to bring in the xml data I have.

Let me describe what I need to accomplish:

1) I am given an xml file only. No other format is availble.
2) I need to scan the file to look for key words and determine their
values.
3) I also need to scan for the employee skill set if it matches a certain
skill set I am looking for and get itheir employee ID number.

That is all I need to do.

Can someone please give me suggestion on the best approach to this problem??

I am using Access 2000 and if needed, I can use Access 2003. The KB article
needed Access 2003 or it gave an error. I understand vba code. I am also
using xp os.

I was thinking on reading the file and looking for the key words, but I have
no idea in bring in an xml file into access???? I can't bring it in as a
table, and I don't think I can use an DAO.Recordset????? I don't know what
ADO recordset does.


Any help would be deeply appreciated!!!

Thank You,

Gary
 
Hi Gary,

How often will you have to do this and are the file contents/element
names/structure stable?

If the XML file is well-formed and the data structure is stable, you could
read the file in using the scriptlet library filesystemobject in Access
2000; look up createfileobject for some code examples. Or, you can use the
old dos style file open, read the file in a line at a time, look for the
tags that encapsulate the content you want, pop that information into an
array, then deal with the 'hits' after you have completed your line by line
scan of the file. You need to understand how the two elements you want to
extract are related to each other. Are they siblings, or is the skill a
child node of the employee? If child, is the relationship one to many? <very
possible> As in more than one skill tag for a given employee?

The point is, you have to browse through the file and see what the exact
tags are and how they are organized - then figure out how to grab the chunk
you want. The code below (substituting your path\filename) will read that
file a line at a time - you can use instr(s, strSkillTag) to test for the
tags whose content you want to capture - then grab everything between the
'>' of the opening tag and the '<' of the respective closing tag.

Hope this helps,
Gordon

Dim fh as integer 'file handle
Dim myfile as string 'path and name of your file
Dim s as string 'holds a line of text

Dim myArray(100,2) as string 'stores the hits could be a lot larger if need
be

myfile = "C:\somefolder\somename.xml"
fh = FreeFile()
open myfile for input as #fh

Do While Not EOF(fh)
line input #fh, s
'process your string, look for the tags you want
'then store them into the array
'myArray(Count,1) = EmpIDContent
'myArray(Count,2) = SkillTagContent
Loop
Close #fh
'Then we process the array, stuff it into a table, whatever
 
Back
Top