SAK のメソッドの例
以下のメソッドの例では、Group オブジェクト内を移動して、その Element オブジェクトおよびそれらの属性のすべてを表示します。
private void displayObjects (Group objects) {
//
// xmlDisplay is a boolean instance variable that defines
// whether the Group should be rendered as XML or as plain
// text.
//
if ( xmlDisplay ) {
PrintWriter pw = new PrintWriter (System.out);
objects.toXML (pw, true, true);
}
else {
int n = objects.getElementCount ();
for ( int i = 0; i < n; ++i ) {
//
// Print one empty line between Elements
//
System.out.println ("");
Element object = objects.getElementAt (i);
Enumeration atts = object.getAtts ();
while ( atts.hasMoreElements () ) {
//
// Render each attribute as "name: value"
// If an attribute is multivalued, indent each
// value such that they are vertically aligned.
//
Att att = (Att)atts.nextElement ();
String name = att.getName ();
System.out.print (name + ": ");
Enumeration values = att.getValues ();
int v = 0;
while ( values.hasMoreElements () ) {
Object value = values.nextElement ();
if ( v++ > 0 ) {
System.out.print (" ");
for ( int s = 0; s < name.length (); ++s )
System.out.print (" ");
}
System.out.println (value);
}
}
System.out.println ("");
}
}