Function: soap-decode-xs-basic-type

soap-decode-xs-basic-type is a byte-compiled function defined in soap-client.el.gz.

Signature

(soap-decode-xs-basic-type TYPE NODE)

Documentation

Use TYPE, a soap-xs-basic-type, to decode the contents of NODE.

A LISP value is returned based on the contents of NODE and the type-info stored in TYPE.

This is a specialization of soap-decode-type for soap-xs-basic-type objects.

Source Code

;; Defined in /usr/src/emacs/lisp/net/soap-client.el.gz
(defun soap-decode-xs-basic-type (type node)
  "Use TYPE, a `soap-xs-basic-type', to decode the contents of NODE.
A LISP value is returned based on the contents of NODE and the
type-info stored in TYPE.

This is a specialization of `soap-decode-type' for
`soap-xs-basic-type' objects."
  (let ((contents (xml-node-children node))
        (kind (soap-xs-basic-type-kind type))
        (attributes (xml-node-attributes node))
        (validate-type type)
        (is-nil nil))

    (dolist (attribute attributes)
      (let ((attribute-type (soap-l2fq (car attribute)))
            (attribute-value (cdr attribute)))
        ;; xsi:type can override an element's expected type.
        (when (equal attribute-type (soap-l2fq "xsi:type"))
          (setq validate-type
                (soap-wsdl-get attribute-value soap-current-wsdl)))
        ;; xsi:nil can specify that an element is nil in which case we don't
        ;; validate it.
        (when (equal attribute-type (soap-l2fq "xsi:nil"))
          (setq is-nil (string= (downcase attribute-value) "true")))))

    (unless is-nil
      ;; For validation purposes, when xml-node-children returns nil, treat it
      ;; as the empty string.
      (soap-validate-xs-basic-type (car (or contents (list ""))) validate-type))

    (if (null contents)
        nil
      (cl-ecase kind
        ((string anyURI QName ID IDREF language) (car contents))
        ((dateTime time date gYearMonth gYear gMonthDay gDay gMonth)
         (car contents))
        ((long short int integer
               unsignedInt unsignedLong unsignedShort nonNegativeInteger
               decimal byte float double duration)
         (string-to-number (car contents)))
        (boolean (string= (downcase (car contents)) "true"))
        (base64Binary (base64-decode-string (car contents)))
        (anyType (soap-decode-any-type node))
        (Array (soap-decode-array node))))))