smayshar
asked on
Why parse an XML file selectNodes doesn't work?
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</co ntactPhone >
<nameOfSchool>Ffff SCHOOL</nameOfSchool>
<position>PRINCIPAL</posit ion>
<type>1</type>
<givenNames>LEISA</givenNa mes>
<surname>NEATON</surname>
<employeeNo>2145</employee No>
<fullName>LEISA NEATON</fullName>
<location>School based</location>
</body2>
- <body2>
<contactPhone>07493153</co ntactPhone >
<nameOfSchool>Fasdf</nameO fSchool>
<position>TEACHER</positio n>
<type>1</type>
<givenNames>Barak</givenNa mes>
<surname>OBAMA</surname>
<employeeNo>2189</employee No>
<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>
.
..
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</co
<nameOfSchool>Ffff SCHOOL</nameOfSchool>
<position>PRINCIPAL</posit
<type>1</type>
<givenNames>LEISA</givenNa
<surname>NEATON</surname>
<employeeNo>2145</employee
<fullName>LEISA NEATON</fullName>
<location>School based</location>
</body2>
- <body2>
<contactPhone>07493153</co
<nameOfSchool>Fasdf</nameO
<position>TEACHER</positio
<type>1</type>
<givenNames>Barak</givenNa
<surname>OBAMA</surname>
<employeeNo>2189</employee
<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
ASKER
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 ???
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 ???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Are the remaining fields filled with an empty string, or is it falling over as nodeR.selectSingleNode("//