Home » Database » MySQL » How to export an ASP Associative Array to XML

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 :

[sourcecode language=”vb”] <!–#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()
%>
[/sourcecode]

And You will get out the following XML:

[sourcecode language=”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>
[/sourcecode]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.