Monday, November 08, 2010 at 12:05 AM.
system.verbs.builtins.soap.decode.main
on main (adrmsg, adrelement, flEnforceSimpleTypes=true) {
<<Changes:
<<03/26/01; 11:51:43 AM by JES
<<Added decoding of Void elements.
<<04/05/01; 9:57:05 PM by JES
<<Get types as determined by the schema namespace URI specified by the message. New optional parameter, flEnforceSimpleTypes, specifies whether to fault on elements whose type is not specified. This is passed to soap.decode.struct and soap.decode.array.
<<05/04/01; 7:20:53 PM by JES
<<If an element has no children, and also has cdata, it's not an empty struct -- it's a simple-type. Decode it as such.
soap.xmlutils.pushScope (adrmsg, adrelement);
local (value, href);
try {
adrelement = soap.xmlutils.resolveHref (adrmsg, adrelement);
if adrelement == false { //decode void elements
local (voidTable); new (tableType, @voidTable);
return (voidTable)};
if soap.xmlutils.hasChildren (adrelement) { //compound type: struct or array?
local (arraytype = soap.xmlutils.getAttributeValue (adrelement, soap.xmlutils.setQualifiedName (adrmsg, "arrayType", soap.constants.nsEncodingURI)));
if arraytype {
value = soap.decode.array (adrmsg, adrelement, arraytype, flEnforceSimpleTypes)}
else { //assume it's a struct
value = soap.decode.struct (adrmsg, adrelement, flEnforceSimpleTypes)}}
else { //simple type
local (type, adrSchemaVersion, schemaURI = soap.constants.nsSchemaURI);
for adrSchemaVersion in @soap.constants.schemaVersions { //find the XML schema URI
schemaURI = adrSchemaVersion^.nsURI;
type = soap.xmlutils.getAttributeValue (adrelement, soap.xmlutils.setQualifiedName (adrmsg, "type", schemaURI));
if type {
break}};
if type {
value = soap.decode.simpleType (adrmsg, adrelement, type)}
else { //maybe it's a nil value, empty struct or empty array?
if flEnforceSimpleTypes {
local (nilattrib = soap.xmlutils.getAttributeValue (adrelement, soap.xmlutils.setQualifiedName (adrmsg, "null", schemaURI)));
if nilattrib == "1" {
value = nil}
else { //11/15/00 JES: handle empty arrays and structs
local (arraytype = soap.xmlutils.getAttributeValue (adrelement, soap.xmlutils.setQualifiedName (adrmsg, "arrayType", soap.constants.nsEncodingURI)));
if arrayType {
value = {}}
else { //empty struct, nil value or non-typed value
if not soap.xmlutils.getFirstChildElement (adrelement) { // empty struct or non-typed scalar
local (cdata = soap.xmlutils.getCharacterData (adrelement));
if cdata == "" { //empty struct
local (t); new (tableType, @t);
value = t}
else {
value = soap.decode.unknownSimpleType (cdata)}}
else {
scripterror ("Can't decode \"" + soap.xmlutils.getElementName (adrelement) + "\" element because no type was specified.")}}}}
else { //try to coerce cdata to some value
value = soap.decode.unknownSimpleType (soap.xmlutils.getCharacterData (adrelement))}}}}
else {
soap.xmlutils.popScope (adrmsg);
scripterror (tryerror)};
soap.xmlutils.popScope (adrmsg);
return (value)}
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.