Re: How Do I search an XML File?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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



"Gary" <Gary@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:EA0F2285-3581-419C-B50E-A6BA912DD79D@xxxxxxxxxxxxxxxx
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


.



Relevant Pages

  • Re: Reading Reults of txt file - and then...
    ... I need it to execute another file if it finds ... >>I am using FSO to read a XML file, using the ReadAll method. ... First how does an XML file appear to wsh? ... > Once you have found these tags (or not, depending on whether or not they are ...
    (microsoft.public.scripting.vbscript)
  • newbie: how to change webpage element dynamically
    ... I need to come up with a way so that when this xml file is opened up ... say class2, the text in between the value tags must change to class2 ... This code will let me display a drop down menu, ... take the selected value and change the text in the value tags. ...
    (comp.lang.javascript)
  • Re: xml to text ???
    ... You can Loadyour text file into an XmlDocument, ... That strips out all of the tags, ... For example, given this XML file, ... XmlDocument doc = new XmlDocument; ...
    (microsoft.public.dotnet.xml)
  • Re: multiline regular expression (replace)
    ... I would like to perform regular expression replace (e.g. removing ... everything from within tags in a XML file) with multiple-line pattern. ... Another is to use \n in your strings to represent newlines. ...
    (comp.lang.python)