CODE ARCHIVE

Years of coding.

Technical articles, programming tutorials, code snippets and source files shared over the years.

Back to all articles

ARTICLES

How to export an ASP Associative Array to XML

"Asp Associative Array Class" provides a method to easly export all items to a well formatted XML string. For example, You can create a new *.ASP file :

<!--#include file="AssociativeArrayClass.asp" -->
<%
Dim Person, God
Set Person = New AssociativeArray
Set God = New AssociativeArray
Person("name") = "Max"
Person("surname") = "Vergelli"
God("name") = "Jesus"
God("surname") = "Christ"
Dim World
Set World = New AssociativeArray
World(1) = Person
World(2) = God
response.Write World.ToXML()
%>
And You will get out the following XML:

<?xml version="1.0" encoding="utf-8"?>
<array>
      <key>
            <name><![CDATA[1]]></name>
            <value>
                    <key>
                           <name><![CDATA[name]]></name>
                           <value><![CDATA[Max]]></value>
                    </key>
                    <key>
                           <name><![CDATA[surname]]></name>
                           <value><![CDATA[Vergelli]]></value>
                   </key>
           </value>
      </key>
      <key>
             <name><![CDATA[2]]></name>
             <value>
                    <key>
                           <name><![CDATA[name]]></name>
                           <value><![CDATA[Jesus]]></value>
                    </key>
                    <key>
                          <name><![CDATA[surname]]></name>
                          <value><![CDATA[Christ]]></value>
                    </key>
             </value>
       </key>
</array>