Service Message Writer

This is used to write requests for other services or to write a response for this service. It provides a simplified syntax for writing XML messages based on the Flat XML conventions.

ServiceMessageWriter = new com.metrici.xerula.ServiceMessageWriter(rootName) Create a new, empty, service message with the given root.

Use the application.newServiceRequest() and application.newServiceResponse() for creating service requests and responses.

put(path,value) Write a value to the message. Returns false if there is an error. There are versions which take strings or numbers.

The only possible error is that the path is not well formed. Scripts need not test for this if they are confident of the well-formedness of their paths.

String = getErrorMessage() Return the error message associated with the most recent put.
String = toString() Get a string view of the service message.

Flat XML

Flat XML is a convention for representing any XML document as a set of name=value pairs. It is used when invoking services.

The basic idea is that any simple XML document can be broken down so that each value is paired with the XPath representation of the containing element or attribute, relative to the root document.

e.g.

/=GetAsset
userLogonReference=john.doe
password=froggy
assetIdentifier=412
UserGroupList/User[1]/userIdentifier=308

Is the same as

<GetAsset>
  <userLogonReference>john.doe</userLogonReference>
  <password>froggy</password>
  <assetIdentifier>412</assetIdentifier>
  <UserGroupList>
    <User>
      <userIdentifier>308</userIdentifier>
    </User>
  </UserGroupList>
</GetAsset>

The rules for this are:

  • The special name / identifies the root element. This implicitly precedes all other elements. This may contain more than one level, e.g. /=Wrapper/Service, but the first level must not contain any position specifiers.
  • Every element has a position. This defaults to 1, so the following are identical:
    userLogonReference=john.doe
    userLogonReference[1]=john.doe
  • Repeating groups are identified by paths with position selectors. These must be numeric, greater than zero. They are output in numerical sequence, and any missing parts are added, e.g.
    x[2]=y

    Gives

    <x/>
    <x>y</x>
  • With the exception of the root element, no name may start or end with a slash.
  • Elements must contain either a value or other elements.
  • Attributes are not supported.
  • Namespaces, comments and processing instructions are not supported.
  • To code an empty element, code the element with empty data, e.g.
    UserGroupList=
  • Duplicates are not permitted, and behaviour on passing duplicates is undefined.
  • name=value pairs are processed in sequence. However, in the case of nested groups, they can be processed out of sequence. (This allows the order of data to be garbled in an interim process, and to be recreated correctly at a later stage.)