469,307 Members | 1,527 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,307 developers. It's quick & easy.

VB6 - Looping thru XML elements into rs using MSXML2.DOMDocument40

3
Hi everyone,

I'm a newbie to the forum.

I have an issue and was hoping to get some assistance/ideas:

Im trying to read a XML file into two record sets.
I can acheive looping through the first level element but i can not loop the the second level (child elements), any ideas??
I need to be able to loop thru each patient record and read into rsPatMeals and secondly loop thru each <meal_selected> and read into rsMeals.
---- xml file---
Expand|Select|Wrap|Line Numbers
  1. <Hospital>    
  2.     <PATIENT>        
  3.         <ur>ppp</ur>        
  4.         <area>Wards</area>        
  5.         <meal_selected>            
  6.             <menuno>67</menuno>                    <mod1>4</mod1>            
  7.             <mod2>12</mod2>        
  8.         </meal_selected>        
  9.         <meal_selected>            
  10.             <menuno>13</menuno>                    <mod1>1</mod1>            
  11.             <mod2>0</mod2>        
  12.         </meal_selected>        
  13.         <meal_selected>            
  14.             <menuno>120</menuno>                    <mod1>0</mod1>            
  15.             <mod2>0</mod2>        
  16.         </meal_selected>        
  17.         <meal_selected>            
  18.             <menuno>124</menuno>                    <mod1>9</mod1>            
  19.             <mod2>0</mod2>        
  20.         </meal_selected>    
  21.     </PATIENT>    
  22.     <PATIENT>        
  23.         <ur>mmm</ur>        
  24.         <area>Wards</area>        
  25.         <meal_selected>            
  26.             <menuno>7</menuno>                    <mod1>0</mod1>            
  27.             <mod2>0</mod2>        
  28.         </meal_selected>        
  29.         <meal_selected>            
  30.             <menuno>22</menuno>                    <mod1>19</mod1>            
  31.             <mod2>0</mod2>        
  32.         </meal_selected>        
  33.         <meal_selected>            
  34.             <menuno>86</menuno>                    <mod1>0</mod1>            
  35.             <mod2>0</mod2>        
  36.         </meal_selected>        
  37.         <meal_selected>            
  38.             <menuno>153</menuno>                    <mod1>0</mod1>            
  39.             <mod2>16</mod2>        
  40.         </meal_selected>    
  41.     </PATIENT>
  42. </Hospital>
---------------------------------------------------------------------
---VB 6 Code----
Expand|Select|Wrap|Line Numbers
  1.   Dim objXMLDOM_patmls As New MSXML2.DOMDocument40
  2.   Dim objPatNodesList As IXMLDOMNodeList
  3.   Dim objPatientNode As IXMLDOMNode
  4.   Dim objMealNodes As IXMLDOMNodeList
  5.   Dim rsPatMeals As New ADODB.Recordset
  6.   Dim rsMeals As New ADODB.Recordset
  7.   Dim pstrSQL As String
  8.  
  9.   objXMLDOM_patmls.async = False
  10.  
  11. objXMLDOM_patmls.Load(App.path & "\xml\patMeals.xml")
  12.   Set rsPatMeals = CreateObject("ADODB.Recordset")
  13.   Set rsMeals = CreateObject("ADODB.Recordset")
  14.  
  15.   Set objPatNodesList =_
  16.  objXMLDOM_patmls.selectNodes("Hospital/PATIENT")
  17.   Set objMealNodes =_  objXMLDOM_patmls.selectNodes"Hospital/PATIENT/meal_selected")
  18.   For Each objPatientNode In objPatNodesList
  19.           rsPatMeals.AddNew
  20.           rsPatMeals.Fields("UR") = objPatientNode.selectSingleNode("ur").nodeTypedValue
  21.           rsPatMeals.Fields("AREA") = objPatientNode.selectSingleNode("area").nodeTypedValue
  22.           rsPatMeals.Fields("WARD") = objPatientNode.selectSingleNode("ward").nodeTypedValue
  23.           rsPatMeals.Fields("BED") = objPatientNode.selectSingleNode("bed").nodeTypedValue
  24.           rsPatMeals.Fields("CYCLE") = objPatientNode.selectSingleNode("cycle").nodeTypedValue
  25.           rsPatMeals.Fields("DOW") = objPatientNode.selectSingleNode("dow").nodeTypedValue
  26.           rsPatMeals.Fields("MLDATE") = objPatientNode.selectSingleNode("mldate").nodeTypedValue
  27.           rsPatMeals.Fields("MEALMODS") = objPatientNode.selectSingleNode("mealmods").nodeTypedValue
  28.           rsPatMeals.Fields("DISCHARGED") = 0  'current ur to be checked against pmi to determin
  29.           rsPatMeals.Fields("SOURCE") = objPatientNode.selectSingleNode("source").nodeTypedValue
  30.           rsPatMeals.Fields("FMSUSER") = "PDS"
  31.           rsPatMeals.Fields("FMSUSERUPDATE") = Now()
  32.           rsPatMeals.Update
  33.   Next objPatientNode
Does anyone have any ideas on how i can loop thru all <meal_selected> for each <patient> and assign to the rsMeals ??

Any help would be greatly appreciated
May 11 '07 #1
1 15399
pds79
3
The FOR loop should look like:
Expand|Select|Wrap|Line Numbers
  1. For Each objPatientNode In objPatNodesList
  2.   rsPatMeals.AddNew
  3.   rsPatMeals.Fields("UR") = objPatientNode.selectSingleNode("ur").nodeTypedValue
  4.   rsPatMeals.Fields("AREA") = objPatientNode.selectSingleNode("area").nodeTypedValue
  5.   rsPatMeals.Update
  6. Next objPatientNode
May 11 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by cppaddict | last post: by
12 posts views Thread by Mark Constant | last post: by
1 post views Thread by bird | last post: by
1 post views Thread by Shaileen Patel | last post: by
2 posts views Thread by pob | last post: by
16 posts views Thread by kaferro | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.