473,324 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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 16576
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

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

Similar topics

3
by: cppaddict | last post by:
Hi, I need to a way to loop thru vectors (or some other appropriate collection type) using constructs such as: for (pr = someVector.begin(); pr != someVector.end(); pr++) ...
12
by: Mark Constant | last post by:
I have a drop-down list now and I got it so when something is selected from the drop down list it calls a JavaScript function. I want it so the value selected from the drop-down list is sent as a...
1
by: wooks | last post by:
I have some information embedded in included schemas which I want to access at run-time for the purposes of contructing a GUI (they will support field labels and tool tips). The options seem to...
1
by: bird | last post by:
?sitem <?xml version="1.0"?> <RootNode> ' one root node <Transaction> ' doc element node <AccountNumber>1001000</AccountNumber> '...
1
by: Shaileen Patel | last post by:
Hi, I am trying to convert a lot of web reports from ASP/VB to ASP.NET/VB.NET. I would like to save my dataset in XML and then use XSLT to transform the XML. The catch is I would like to have...
2
by: pob | last post by:
Whats the difference between using a control or a listbox when looping thru a listbox. In example 1 it dims a listbox and an example 2 it dims a control. Please explain. Thanks in advance ...
16
by: kaferro | last post by:
What is the typical way to loop through a vector while deleting certain elements during the loop process? The code below works, but I am wondering if there is a better solution. ...
1
by: PedroVision | last post by:
Greetings All... When I try to debug my .Net program...I get the following 2 errors... Error 1 Type 'Msxml2.DOMDocument40' is not defined. Error 2 Type 'IXMLDOMNode' is not defined. I think...
6
by: mahowe | last post by:
Hi, I have had this problem for a while and have not been able solve it. What im looking at doing is looping thru my patient table and trying to organise the patients in to there admission...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.