Skip to main content
Version: Next

XML DECODE

XML DECODE ( xmlValue ; 4Dvar )

ParameterTypeDescription
xmlValueTextText type value coming from an XML structure
4DvarField, Variable4D variable or field receiving the converted XML value

Description

The XML DECODE command converts a value stored as an XML string into a 4D typed value. The conversion is carried out automatically according to the following rules:

ValueExamplesConversion on English system
number8,58.5Real: 8.5
Boolean1 0 or true falseBoolean: True/False
BLOBBase64 decoding
PictureBase64 decoding + BLOB to picture command
Dates2009-10-25T01:03:20+01:00!10/25/2009! -> Deletion of time part as well as time zone
Time2009-10-25T01:03:20+01:00?01:03:20? -> Deletion of date part. Warning: time zone is taken into account if different from local time. For example: "2009-10-25T01:03:20+05:00" will be decoded ?21:03:20? in UTC+1 local time

If the 4Dvar parameter type is not defined, the text type is used by default.

Example

Importing data from an XML document in which values are stored as attributes.
Example of XML document:

 Repeat
    MyEvent:=SAX Get XML node(DocRef)
 
    Case of
       :(MyEvent=XML Start Element)
          ARRAY TEXT(arrAttrNames;0)
          ARRAY TEXT(arrAttrValues;0)
          SAX GET XML ELEMENT(DocRef;vName;vPrefix;arrAttrNames;arrAttrValues)
          If(vName="CD")
             CREATE RECORD([CD])
             For($i;1;Size of array(arrAttrNames))
                $attrName:=arrAttrNames{$i}
                Case of
                   :($attrName="CD_ID")
                      XML DECODE(arrAttrValues{$i};[CD]CD_ID)
                   :($attrName="Title")
                      [CD]Work:=arrAttrValues{$i}
                   :($attrName="Price")
                      XML DECODE(arrAttrValues{$i};[CD]Price)
                   :($attrName="Date")
                      XML DECODE(arrAttrValues{$i};[CD]Date entered)
                   :($attrName="Duration")
                      XML DECODE(arrAttrValues{$i};[CD]Total_duration)
                   :($attrName="Double")
                      XML DECODE(arrAttrValues{$i};[CD]Double_CD)
                End case
             End for
          End if
          ...
    End case
 Until(MyEvent=XML End Document)

See also

BASE64 DECODE
BASE64 ENCODE

Properties

Command number1091
Thread safe