Database Reference
In-Depth Information
// query members from the cube
results = cube.queryMembers("<CHILDRENOF Product <SORTNONE
<FORMAT {MBRNAMES ALTNAMES
LEVELNUMBERS}");
Note: There is one unusual behavior with the <FormAt command that you need to
be aware of. The <FormAt command and the opening curly bracket ( { ) must be
separated by a space. If you fail to separate these items by a space, the first property you
specify inside the curly brackets will not be returned.
This query returns the following tab-delimited string.
Product\t\t2\t100\tColas\t1\t200\tRoot Beer\t1\t300\tCream Soda\t1\
t400\tFruit Soda\t1\tDiet\tDiet Drinks\t1
Though you can parse multiple members that are tab-delimited, there is a better way.
you can specify different delimiters for the members and for the properties. If we make
a minor modification to the query, we can return each member on its own line.
// query members from the cube
results = cube.queryMembers("<NEWLINESEPARATED
<CHILDRENOF Product
<SORTNONE
<FORMAT {ALTNAMES MBRNAMES
LEVELNUMBERS}");
The output looks a bit different. The \n is the Java escape sequence for a newline
character.
Product\t\t2\n
100\tColas\t1\n
200\tRoot Beer\t1\n
300\tCream Soda\t1\n
400\tFruit Soda\t1\n
Diet\tDiet Drinks\t1\n
If you change the delimiters, you also need to change the parsing routines. you can
use an algorithm that first splits the string on the newline character to return an array of
member lines, and then split each line on the tab character to parse the properties. here
is the earlier parsing example rewritten to use a double loop.
// split into lines using the newline character
memberArray = results.split("\n");
// loop the array elements
for (String name : memberArray) {
// split the properties on the tab character
String[] properties = name.split(“\t”);
// print the properties
System.out.println("Name: " + properties[0]
+ " | Alias: " + properties[1]
+ " | Level: " + properties[2]);
}
Search WWH ::




Custom Search