That was a great post mate. As you mentioned the tips for reading the XML, now you need to Write the XML. This is the form in which we have our data:
Code:
personnes = array () Redim personnes ( 1 ) georges = array () Redim georges ( 4 ) georges ( 0 ) = " Baud " georges ( 1 ) = " Georges " georges ( 2 ) = " Marié " georges ( 3 ) = 49 enfants = array () Redim enfants ( 0 ) elisabeth = array () Redim elisabeth ( 1 ) elisabeth ( 0 ) = " Tiop " elisabeth ( 1 ) = " Elisabeth " enfants ( 0 ) = elisabeth georges ( 4 ) = enfants personnes ( 0 ) = georges judith = array () Redim judith ( 4 ) judith ( 0 ) = " Trinzka " judith ( 1 ) = " Judith " judith ( 2 ) = " Célibataire " judith ( 3 ) = 22 judith ( 4 ) = array () personnes ( 1 ) = judith
And it will transform into a XML in the same form as the previous chapter we read. For writing, we will also need to initialize and configure our parser:
Code:
Set xmlDoc = CreateObject ( " Microsoft.XMLDOM " ) Set oCreation = xmlDoc . createProcessingInstruction ( " xml " , " version='1.0' encoding='ISO-8859-1' " ) xmlDoc . insertBefore oCreation, xmlDoc . childNodes . Item ( 0 )
The 2 lines after the initialization can generate the XML header. Then we will create the root and add to the document:
Code:
Set root = xmlDoc . createElement ( " personnes " ) xmlDoc . appendChild (root)
We therefore used the method createElement to create a new node and appendChild method to add the node to the document root. We will now go through our people to create an array element for each individual array elements:
Code:
For Each personne In personnes Set personneElement = xmlDoc . createElement ( " personne " ) root . appendChild (personneElement) Next
This time, they added items into the root node. We will now add key information about the person:
Code:
Set personneElement = xmlDoc . createElement ( " personne " ) Set nomElement = xmlDoc . createElement ( " nom " ) nomElement . Text = personne ( 0 ) personneElement . appendChild (nomElement) Set prenomElement = xmlDoc . createElement ( " prenom " ) prenomElement . Text = personne ( 1 ) personneElement . appendChild (prenomElement) Set etatElement = xmlDoc . createElement ( " etat " ) etatElement . Text = personne ( 2 ) personneElement . appendChild (etatElement) root . appendChild (personneElement)
If there are children, then we create a child element with the addition of child elements for each child of the person and finally we add a name and a surname for each child. Now save our file.
Bookmarks