New in version 6.1.0: See the new features.

Read a web stdin XML content

read_web_xml_values()

Read a web stdin XML content into a !record


SYNTAX

read_web_xml_values(recordId [, options])

This method is only available in nph-srep.

Read into the record the received stdin XML content (if nph-srep is executed from a web server the content is received from the client “browser” as the message content in a PUT or POST method)

The content is converted from utf8 to the system native enconding.

recordId

Record where to read the XML values into

options

None for the read operation

It returns the number of keys read from the XML content (0 if none)

Note

New in version 6.2.0: See the new features.

  • Nested objects are supported since the nested record feature (see read_xml_values example)

  • The field arrays can be autoredim’ed if the “a” flag is set.

  • The !record arrays can be autoredim’ed if the RECFL_AUTOREDIM flag is set.

  • To address the problem of reading/writting a json/xml tag which happens to be a Sculptor reserved word (creating a field on a record with that name is not possible). It’s possible to define the reserved word with an underscore “_” in front of it. Not clashing with the reserved word any more. As a rule, when writting/reading the first “_” will be removed (if an underscore is needed just add one more). E.g:

    !record Rec {
        _image,,a64
    }
    
  • Now the function treats an ASCII or binary array with a “p” (packed flag) flag as one big field, so that large XML fields can be read. E.g.:

    !record Rec {
        large8kDataString,,a128[64],,p
    }
    

EXAMPLE

This nph-srep example reads a JSON or an XML request depending on the CONTENT_TYPE received:

!record postRequest {
    testI4,,i4
    testR8,,r8
    testA32,,a32,,v
}

/* Check that the post method is used */
if (get_web_method() <> METHOD_POST) {
    web_status(405, "METHOD NOT SUPPORTED")
    end
}

/* Get the request values */
switch (getenv("CONTENT_TYPE")) {
case = "application/json":
    read_web_json_values(postRequest)
    break

case = "application/xml":
    read_web_xml_values(postRequest)
    break

default:
    web_status(415, "MEDIA TYPE NOT SUPPORTED")
    put "Server does not support the media type"
    end
}
...

RELATED TOPICS

Creating web pages with Sculptor

Internet functions

print_xml

JSON and XML functions

!record

JSONXML_ options