# XMLTODYN

Updated: 10/19/2021, 9:29:48 PM
Created: 10/19/2021, 9:29:48 PM
Last Updated By: Kevin Munoz
Read Time: 1 minute(s)

# Description

This function converts XML to a dynamic array. Optionally, a transform may be used to convert the XML content. The function takes the general form:

XMLTODYN(XML,XSL,result)
1

Where:

XML is the content to be converted,

XSL is the optional transform

If result = 0,  Array will contain a dynamic array built from the xml / xsl

If result != 0, Array will contain an error message

There is no requirement for xsl if generic xml is being reconverted to dynarray. An example of use is as:

ARR_VAR = "Tom" : @AM : "Dick" : @AM : "Harry"
XML_VAR = DYNTOXML(ARR_VAR,"",result)
DYN_ARR = XMLTODYN(XML_VAR,"",result)
CRT CHANGE(DYN_ARR ,@AM," ")
1
2
3
4

to output:

Tom Dick Harry
1

If passing a stylesheet in the second parameter, it performs a transform to give a different format of the array.

An example of use would be as :

a = XMLTODYN(xml,xsl,rc)
CRT CHANGE(a,@AM," ")
1
2

given:

# XML Contents

<?xml version="1.0" encoding="UTF-8"?>
<mycustomer>
<firstname>Tom</firstname>
<lastname>Dick</lastname>
<address>Harry</address>
</mycustomer>
1
2
3
4
5
6

and

# XSL Contents

<xsl:template match="mycustomer">
<array>
<xsl:apply-templates/>
</array>
</xsl:template>
<xsl:template match="firstname">
<data>
<xsl:attribute name="attribute">1</xsl:attribute>
<xsl:attribute name="value">
<xsl:number level="single"/>
</xsl:attribute>
<xsl:attribute name="subvalue">1</xsl:attribute>
<xsl:value-of select="."/>
</data>
</xsl:template>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

Go back to jBASE BASIC

Go back to Programmers' Reference Guide