Looping through document fields getting the string names and

I have searched high and low and can’t find a good method of looping through a document retrieving the string names and values.

For example, I have the following XML that is converted into a document:

<STATUS_MSG>
ASSET NOT ON FILE
INVALID ACCOUNT
INVALID ASSET TYPE
CANNOT BE RELEASED
ORDER NOT ACCEPTED
</STATUS_MSG>

The result of converting this to a document is a document named STATUS_MSG and 3 fields named SMO008, SMO009, SMO020 and a string list named ALERT.

There are over 20 fields and instead of coding for each specific field I would rather repeat through the document getting each string name and value. For example, on the first iteration I would retrieve the string name SMO008 and the value ASSET NOT ON FILE.

Does anybody have a solution or suggestion?

Thanks!

What you’re trying to do with the data may help a bit here, but you can write a small Java service that loops over the entries in the Document. For example:

public static void MyService(IData pipline)
{
  IDataCursor cursor = pipeline.getCursor();

  while (cursor.next())
  {
    String key = cursor.getKey();
    Object value = cursor.getValue();
    // do whatever you need
  }
  cursor.destroy();
}

This handles a flat structure of key/values. To handle nested data all you need to do is check the type of value. If it’s an IData you can recursively call the same service.

Try this service in WmPublic:

(IS 4.6) pub.record:recordToRecordList
(IS 6.x) pub.document:documentToDocumentList

It takes three inputs:

  1. Your document
  2. A name for the keys, eg. key
  3. A name for the values, eg. value

It returns a record/document list, each document having two fields:

  1. With the name you specified in point 2 above, the original name of the field from your document.
  2. With the name you specified in point 3 above, the value of the field.

HTH.