Solved

Why parse an XML file selectNodes doesn't work?

Posted on 2009-03-31
3
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…

636 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