Monday, November 08, 2010 at 12:05 AM.
system.verbs.builtins.soap.encode.array
on array (adrmsg, listvalue, adrparent, name, customStructType=nil, customNamespace=nil, customNamespaceURI=nil, flEntityEncodeHighAscii=false) {
<<Changes:
<<03/19/01; 3:24:31 PM by JES
<<Added support for encoding arrays of structs.
<<03/27/01; 5:44:21 PM by JES
<<Serialize doubles as type "xsd:float", instead of "xsd:double", since float means 32-bit floating point number, and double means 64-bit floating point number. In Frontier, a doubleType is 32-bits.
<<03/29/01; 4:33:39 AM by JES
<<Added xsi:type="SOAP-ENV:Array" attribute to the array element for interop with Apache SOAP.
<<04/03/01; 7:51:02 PM by JES
<<New optional parameter, flEntityEncodeHighAscii, specifies whether to entity-encode high-ascii characters when encoding strings. Default is false. This is passed to soap.encode.main and soap.encode.simpleType.
<<04/07/01; 7:23:05 PM by JES
<<Changed name of customArrayType parameter to customStructType. Pass customStructType, customNamespace and customNamespaceURI in the call to soap.encode.main.
local (item, prevtype, flonetype = true);
local (nsSchemaDataPrefix = soap.constants.nsSchemaDataPrefix);
local (adrelement = soap.xmlutils.addElement (adrparent, name));
bundle { //add the xsi:type attribute
soap.xmlutils.addAttributeValue (adrelement, soap.constants.nsSchemaPrefix + ":type", soap.constants.nsEncodingPrefix + ":Array")};
for item in listvalue {
local (itemtype = typeof (item));
if prevtype {
flonetype = (itemtype == prevtype)}
else {
prevtype = itemtype};
if not flonetype {
break}};
local (type);
if sizeOf (listvalue) == 0 { //11/15/00 JES: handle empty arrays
type = "ur-type"}
else {
if flonetype {
case (prevtype) {
stringType {
type = "string"};
charType {
type = "byte"};
longType;
longType;
intType {
type = "int"};
booleanType {
type = "boolean"};
doubleType {
type = "float"};
<<type = "double"
shortType {
type = "short"};
binaryType {
type = "base64"}}
else { //it's a custom type -- most likely an array of structs
bundle { //reality checks
if customNamespace == nil {
scriptError ("Can't encode \"" + name + "\" array because no namespace was specified.")};
if customNamespaceURI == nil {
scriptError ("Can't encode \"" + name + "\" array because no namespace URI was specified.")};
if customStructType == nil {
scripterror ("Can't encode \"" + name + "\" array because no type was specified.")}};
soap.xmlutils.declareNamespaceInElement (adrelement, customNamespace, customNamespaceURI);
nsSchemaDataPrefix = customNamespace;
type = customStructType}}
else {
type = "ur-type"}};
local (arraytype = nsSchemaDataPrefix + ":" + type + "[" + sizeOf (listvalue) + "]");
soap.xmlutils.addAttributeValue (adrelement, soap.constants.nsEncodingPrefix + ":arrayType", arraytype);
for item in listvalue {
case typeOf (item) {
tableType { //03/18/2001 JES: support arrays of structs
soap.encode.main (adrmsg, item, adrelement, "item", customStructType, customNamespace, customNamespaceURI, flEntityEncodeHighAscii)}}
else {
soap.encode.simpleType (adrmsg, item, adrelement, "item", not flonetype, flEntityEncodeHighAscii)}};
return (adrelement)}
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.