Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Why parse an XML file selectNodes doesn't work?

Posted on 2009-03-31
3
Medium Priority
?
321 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

877 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