About xml

Y

yael

Hi,
How can I create/write into xml file from vba + access 2003?
This code read from xml file into the form.
every form control = element in the xml (names)
the xml file with 1 level.

Public Sub ImportToXML(sFullPath As String, frm As Form)
On Error Resume Next

'XML DOM objects
Dim objDomDoc As New DOMDocument
Dim sName As String
Dim sCtrlName As String
Dim value As Variant
Dim size As Long
Dim index As Long
Dim ctrl As Control

'Open DOM object by loading the xml file.
objDomDoc.async = False
objDomDoc.Load sFullPath

size = objDomDoc.documentElement.childNodes.length
For index = 0 To size
sName = objDomDoc.documentElement.childNodes.Item(index).baseName
value = objDomDoc.documentElement.childNodes.Item(index).nodeTypedValue
For Each ctrl In frm.Controls
sCtrlName = UCase(ctrl.name)
If sCtrlName = sName Then
ctrl = value
End If
Next
Next index

Set objDomDoc = Nothing
End Sub

<?xml version="1.0" encoding="UTF-8"?>
<ONE_USER>
<CONTACT_TYPE_ID>4</CONTACT_TYPE_ID>
<JOB_COMMITTEE>1</JOB_COMMITTEE>
<PROFESSION_ID>2</PROFESSION_ID>
<LOGIN>3</LOGIN>
<SITE_ID>4</SITE_ID>
<DIVISION>5</DIVISION>
<FIRST_NAME>6</FIRST_NAME>
<LAST_NAME>7</LAST_NAME>
<TITLE>8</TITLE>
<ACADEMIC_TITLE>9</ACADEMIC_TITLE>
<DEPARTMENT_SITE_ID>10</DEPARTMENT_SITE_ID>
<TITLE_ID>11</TITLE_ID>
<CERTIFICATION_DATE>12</CERTIFICATION_DATE>
<QUALIFICATION>13</QUALIFICATION>
<ID_NUMBER>14</ID_NUMBER>
<PHONE>15</PHONE>
<FAX>16</FAX>
<MOBILE>17</MOBILE>
<EMAIL>18</EMAIL>
</ONE_USER>

Thank's,
Yael.
 
Y

yael

And what is better: my import method or to use with:
==================================
Dim objDomDoc As New DOMDocument
objDomDoc.async = False
objDomDoc.Load sFullPath
==================================
Dim xmlDoc
Set xmlDoc = CreateObject("MSXML2.DOMDocument")
xmlDoc.async = False
xmlDoc.validateOnParse = True
success = xmlDoc.Load(sFullPath)==================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top