Avatar billede 44nato44 Nybegynder
12. december 2008 - 14:27 Der er 10 kommentarer og
1 løsning

updatere xml fil fra MS Access

Hej

Jeg tror ikke dette er så svært men jeg kan ikke finde noge steder hvor jeg kan få hjælp.

I stedet for at exportere hele db'en til xml for hver updatering, så vil jeg kun ha' opdateret den entry som bliver opdatered i xml filen.

Alt hjælp er velkommen :)

Det her skriver det ud :

Dim xmldoc As MSXML2.DOMDocument60
Set xmldoc = New MSXML2.DOMDocument60

xmldoc.async = False

If xmldoc.Load("C:\Users\Torben Henriksen\Documents\MS Access\Users.xml") Then
    Debug.Print xmldoc.XML
End If

Udskrivnin :

<?xml version="1.0"?>
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Users.xsd" generated="2008-12-12T12:26:41">
    <Users>
        <ID>1</ID>
        <Full_x0020_Name>Torben</Full_x0020_Name>
    </Users>
    <Users>
        <ID>2</ID>
        <Full_x0020_Name>Carsten</Full_x0020_Name>
    </Users>
    <Users>
        <ID>3</ID>
        <Full_x0020_Name>Rob</Full_x0020_Name>
    </Users>
    <Users>
        <ID>4</ID>
        <Full_x0020_Name>Dada</Full_x0020_Name>
    </Users>
</dataroot>
Avatar billede terry Ekspert
13. december 2008 - 10:59 #1
"...I stedet for at exportere hele db'en til xml for hver updatering.."

Can you explain what your using the XML for, Access db's arent normally in XML format and it wouldnt be necessary to export to XML to update.

Mor info please
Avatar billede 44nato44 Nybegynder
13. december 2008 - 13:15 #2
I read some web pages (http://www.thescarms.com/xml/domtutorial.aspx) where it states that its possible to update a xml document.

But how to use that with ms access, does not seem to be so straight forward.

I have a friend who is making a flash site and will need this data in a xml format, which is why I woul like to find a way to make some kind of udate to the xml per update in the database.

Any ideas ?
Avatar billede terry Ekspert
13. december 2008 - 13:55 #3
Where does Access come into the picture? Are you saying that if an update occurs in the database then you also want to update the XML?

If the database is on a web site then I dont think you can run the code (VBA) in your Access dB..
Avatar billede 44nato44 Nybegynder
13. december 2008 - 14:44 #4
The update comes from a form inside the ms access db, which is why I thought the vba code would be the best solution.

It has to be an automatic process as the user should not need to do anything in updating the xml file.
Avatar billede terry Ekspert
13. december 2008 - 15:11 #5
I'm trying to get a complete picture of what your trying to do.

So the Access db is NOT on a web site?
In the dB you have one or more tables and one or more forms?
You update one of the tables through one of the forms?
After the update you want to update an XML document?
Does the XML document contain the same data as the table you just updated and you want to update the same record?

You can import/export XML to/from Access, so you coul djust update in the tabel and then export it.
Avatar billede 44nato44 Nybegynder
13. december 2008 - 16:05 #6
sorry that I am not that clear :

ms access is on a file server together with the xml file containing the same structure and data as in the ms access db.

The plan is :
user open ms access which opens a form where the user can update the users table.
the user makes an update and click a button to save the changes to the db.
In the same script when the db gets updated, it should also make the same changes in the xml document.

I tested with the entire export to xml, but it takes too long (this is just a test example the real db is about 8 mb). The ms access is on a network drive and the users are on different physical locations. (The network might just be too slow, but I am sure they will not upgrade their network  ;)  )

Hope this clears it up a bit
Avatar billede terry Ekspert
13. december 2008 - 16:41 #7
If exporting to xml takes too long then I cant see that reading/writing the XML file is going to be faster.

I dont work so much with XML bu the link you gave above seems streight forward enough.

Have you tried making any code to open the file and loop through the records?
Avatar billede 44nato44 Nybegynder
13. december 2008 - 17:22 #8
This is probably where I hit the wall, I have tried to loop but being able to update a  an entry that I want seems harder than such.

I can update the first entry in the xml file, but other onces seems harder than such.

Here is the coding I have now, there is a lot of garbage code as I am not sure how to do this:

Sub SelectSingleNode()

Dim xmlDoc As MSXML2.DOMDocument60
Dim xmlSingleNode As MSXML2.IXMLDOMNode
Dim xmlNodeListKey As MSXML2.IXMLDOMNodeList
Dim myNodeKey As MSXML2.IXMLDOMNode
Dim ElemList As IXMLDOMNodeList
Dim ElemListName As IXMLDOMNodeList
Dim root As IXMLDOMElement
Dim child As IXMLDOMNode

Dim etst As MSXML2.IXMLDOMNode
Set xmlDoc = New MSXML2.DOMDocument60
Set root = xmlDoc.documentElement
Dim i

xmlDoc.async = False


xmlDoc.Load ("C:\Users\Torben Henriksen\Documents\MS Access\Users.xml")

Set xmlSingleNode = xmlDoc.SelectSingleNode("//Full_x0020_Name")
Set xmlNodeListKey = xmlDoc.selectNodes("//ID")
Set ElemList = xmlDoc.getElementsByTagName("ID")
Set ElemListName = xmlDoc.getElementsByTagName("Full_x0020_Name")
For Each myNodeKey In xmlNodeListKey

For i = 0 To (ElemList.length - 1)

If ElemList.Item(i).Text = "2" Then

Set xmlSingleNode = xmlDoc.SelectSingleNode("//Full_x0020_Name")

Debug.Print ElemList.Item(i).XML
Debug.Print ElemListName.Item(i).XML

' The singleNode only give the first in the list
' xmlSingleNode.Text = "Torben" & i

'xmlDoc.Save "C:\Users\Torben Henriksen\Documents\MS Access\Users.xml"

End If
Next
Next myNodeKey

Set xmlDoc = Nothing

End Sub
Avatar billede terry Ekspert
14. december 2008 - 10:46 #9
If you can send me your dB and an example of the XML then maybe I can get it to work.
ekspertenATsanthell.dk
AT = @
Avatar billede 44nato44 Nybegynder
20. december 2008 - 10:50 #10
Cheers Terry, I figured it out

Thanks and enjoy Christmas next week
Avatar billede terry Ekspert
20. december 2008 - 13:32 #11
Merry Christmas and a good New Year to you too.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester