473,372 Members | 1,103 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,372 software developers and data experts.

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

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
  9.   objXMLDOM_patmls.async = False
  11. objXMLDOM_patmls.Load(App.path & "\xml\patMeals.xml")
  12.   Set rsPatMeals = CreateObject("ADODB.Recordset")
  13.   Set rsMeals = CreateObject("ADODB.Recordset")
  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 16585
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

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++) ...
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...
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...
by: bird | last post by:
?sitem <?xml version="1.0"?> <RootNode> ' one root node <Transaction> ' doc element node <AccountNumber>1001000</AccountNumber> '...
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...
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 ...
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. ...
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...
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...
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: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.