You can get a collection of document variables using the Document.Variables property. Variable names and values are strings.
Example
Shows how to enumerate over document variables.
[Java]
Document doc = new Document(getMyDir() + "Document.doc");
for (java.util.Map.Entry entry : doc.getVariables())
{
String name = entry.getKey().toString();
String value = entry.getValue().toString();
// Do something useful.
System.out.println(MessageFormat.format("Name: {0}, Value: {1}", name, value));
}