Solved

Why parse an XML file selectNodes doesn't work?

Posted on 2009-03-31
3
311 Views
Last Modified: 2013-11-05
I'm using SelectNodes from XMLDocument (In access 2003) in order to read all of the Nodes contained in the file, but I'm having some problems to get the second and third nodes in a loop.

When using this vb code, I receive two records of the first node ("//body2")
And go on to the rest of the xml, how do I get the individual values?


The xml doc start like :  
 <?xml version="1.0" encoding="UTF-8" ?>
- <form1>
 .
 .
 .
- <section2>
  <header2 xmlns:xfa="http://www...../schema/xfa-data/1.0/" xfa:dataNode="dataGroup" />
- <body2>
  <contactPhone>07493153</contactPhone>
  <nameOfSchool>Ffff SCHOOL</nameOfSchool>
  <position>PRINCIPAL</position>
  <type>1</type>
  <givenNames>LEISA</givenNames>
  <surname>NEATON</surname>
  <employeeNo>2145</employeeNo>
  <fullName>LEISA NEATON</fullName>
  <location>School based</location>
  </body2>
- <body2>
  <contactPhone>07493153</contactPhone>
  <nameOfSchool>Fasdf</nameOfSchool>
  <position>TEACHER</position>
  <type>1</type>
  <givenNames>Barak</givenNames>
  <surname>OBAMA</surname>
  <employeeNo>2189</employeeNo>
  <fullName>Barak OBAMA</fullName>
  <location>School based</location>
  </body2>
  <addBody2 xmlns:xfa="http://www...../schema/xfa-data/1.0/" xfa:dataNode="dataGroup" />
  <Validate2 xmlns:xfa="http://www..../schema/xfa-data/1.0/" xfa:dataNode="dataGroup" />
  </section2>

.
..
...

 Dim nodeR As IXMLDOMNode

 

    For Each nodeR In xmlFile.selectNodes("//body2")

        rst.AddNew

        rst!fldAppID = AppID

        rst!fldsName = nodeR.selectSingleNode("//surname").Text

        rst!fldgNames = nodeR.selectSingleNode("//givenNames").Text

        rst!fldPosition = nodeR.selectSingleNode("//position").Text

        rst!fldEORC = nodeR.selectSingleNode("//type").Text

        rst!fldEmployeeID = nodeR.selectSingleNode("//employeeNo").Text

        rst!fldPh = nodeR.selectSingleNode("//contactPhone").Text

        rst!fldSchoolDepartm = nodeR.selectSingleNode("//nameOfSchool").Text

        rst.Update

    Next nodeR

Open in new window

0
Comment
Question by:smayshar
  • 2
3 Comments
 
LVL 15

Expert Comment

by:oobayly
ID: 24039690
So, fldName is being filled from <surname>, and fldNames is filled from <givenNames>?
Are the remaining fields filled with an empty string, or is it falling over as nodeR.selectSingleNode("//position") is Nothing?
0
 

Author Comment

by:smayshar
ID: 24055793
I am not sure that I understand your qustion, the records in the rst after running the code lokks like this:

NEATON LEISA PRINCIPAL 1 2145 07493153 Ffff SCHOOL
NEATON LEISA PRINCIPAL 1 2145 07493153 Ffff SCHOOL

insdeat of :

NEATON LEISA PRINCIPAL 1 2145 07493153 Ffff SCHOOL
OBAMA  Barak  TEACHER  1 2189........

it goes over the first node 2 times and contintue for the rest of the xml why ???
0
 
LVL 15

Accepted Solution

by:
oobayly earned 500 total points
ID: 24057895
Aha, now it makes sense. What's happening is that you are using // in the xpath query.
Do the following and it should work, as it's selecting only the named node in nodeR, not the whole document.

For more information on how xpath works, have a look at this site:
http://www.w3schools.com/xpath/xpath_syntax.asp
rst!fldsName = nodeR.selectSingleNode("surname").Text

Open in new window

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now