Building a Document from a List

In these final samples, the use of list documents is demonstrated. Once an XML document built from a list has been closed, it may be manipulated in the same manner as any other XML document.

The first sample shows how a vector of struct classes can be added to an XML document.

Figure 1. Adding a List to a Document
import curam.util.xml.impl.XMLEncodingConstants;
import curam.util.xml.impl.XMLDocument;

public class XMLSample {
  void listDoc1(MyStructList myStructList) {
    XMLDocument myDoc =
      new XMLDocument(XMLEncodingConstants.kEncodeISOLATIN1);

    myDoc.openForList("A User",
                      "31-Dec-1999",
                      "1.0",
                      "Sample 1");

    myDoc.add(myStructList);
    myDoc.close();

    // The document may now be manipulated as before.
  }
}

In the second sample below, the list of struct classes is iterated over and only those elements whose value field is greater than 100 are added to the document. You can, of course, apply any condition you like to this basic pattern. In IBM Cúram Social Program Management, the list of a type called MyStruct is called MyStructList, and the dtls field of the list is a java.util.Vector of the basic struct class type, this is assumed below.

Figure 2. Adding Elements of a List to a Document
import curam.util.xml.impl.XMLEncodingConstants;
import curam.util.xml.impl.XMLDocument;

public class XMLSample {
  void listDoc2(MyStructList myStructList) {

    XMLDocument myDoc = new XMLDocument(
        XMLEncodingConstants.kEncodeISOLATIN1);

    myDoc.openForList("A User",
                      "31-Dec-1999",
                      "1.0",
                      "Sample 1");

  for (int i = 0; i < myStructList.dtls.size(); i++) {
    if (myStructList.dtls.item(i).value > 100) {
      myDoc.add(myStructList.dtls.item(i));
    }
  }
  myDoc.close();

  // The document may now be manipulated as before.
}