27 October 2008

Xcelsius and White Space Characters

As you begin to familiarize yourself with Xcelsius, not only will you being to appreciate it for its features but also for its irritating and time consuming bugs.

Xcelsius has a control called a Combo Box. A Combo Box simply takes a list of values as a parameter and displays it a nice drop down list that the user can select.

Assuming you have the following list of values saved in a Microsoft Excel sheet as follows:

1
2
3
4
5


The Combo Box will display the above values in a drop down list correctly, allowing the user to select any number from 1 through 5. What if you have a list of values as follows:

1 \n
2 \t
3 \0
4 \r
5 \x0B


Notice the characters in bold following the numeric characters? Those are called white space characters and word processors or editors, such as Microsoft Excel, will ignore them. When viewing a document in them, they will be invisible to the naked eye, that is why they are also sometimes referred to as hidden characters.

Usually, as a human, you won't actually type these characters yourself as they represent special formatting in an output. For example, \n represents a new line feed and \r represents a carriage return. The problem is when you are dynamically inserting this list of values in the Microsoft Excel sheet that is feeding the Combo Box.

So why is this a problem? Xcelsius, unlike Microsoft Excel, will not ignore these characters and actually consider them when generating its drop down list. The end result? The Combo Box will be empty! Xcelsius will go nuts when it detects these characters and simply refuse to render the list of values in the Combo Box.

Solution:
The solution to this problem is actually much easier than it may seem. When your inserting data dynamically, make sure that you trim it to remove any white space characters they may contain.

In PHP, I might do something like this:

<?php

// Fetch Data From A Data Source.

//
// For this example, the Data Source is simply a hard
// coded Array.

$dataSource = array( 'Element 0' , 'Element 1 ' );


// Loop Through Data.
//
// Notice we are trimming the data.

foreach( $dataSource as &$element ) {

$element = trim( $element );
}

// Generate XML.
//
// ...


?>


The idea is basically the same regardless of which programming language you choose. The lesson to be learned here? Always trim your data!

No comments:

Post a Comment

Feel free to write any comments or ideas!

Xcelsius and White Space Characters

As you begin to familiarize yourself with Xcelsius, not only will you being to appreciate it for its features but also for its irritating and time consuming bugs.

Xcelsius has a control called a Combo Box. A Combo Box simply takes a list of values as a parameter and displays it a nice drop down list that the user can select.

Assuming you have the following list of values saved in a Microsoft Excel sheet as follows:

1
2
3
4
5


The Combo Box will display the above values in a drop down list correctly, allowing the user to select any number from 1 through 5. What if you have a list of values as follows:

1 \n
2 \t
3 \0
4 \r
5 \x0B


Notice the characters in bold following the numeric characters? Those are called white space characters and word processors or editors, such as Microsoft Excel, will ignore them. When viewing a document in them, they will be invisible to the naked eye, that is why they are also sometimes referred to as hidden characters.

Usually, as a human, you won't actually type these characters yourself as they represent special formatting in an output. For example, \n represents a new line feed and \r represents a carriage return. The problem is when you are dynamically inserting this list of values in the Microsoft Excel sheet that is feeding the Combo Box.

So why is this a problem? Xcelsius, unlike Microsoft Excel, will not ignore these characters and actually consider them when generating its drop down list. The end result? The Combo Box will be empty! Xcelsius will go nuts when it detects these characters and simply refuse to render the list of values in the Combo Box.

Solution:
The solution to this problem is actually much easier than it may seem. When your inserting data dynamically, make sure that you trim it to remove any white space characters they may contain.

In PHP, I might do something like this:

<?php

// Fetch Data From A Data Source.

//
// For this example, the Data Source is simply a hard
// coded Array.

$dataSource = array( 'Element 0' , 'Element 1 ' );


// Loop Through Data.
//
// Notice we are trimming the data.

foreach( $dataSource as &$element ) {

$element = trim( $element );
}

// Generate XML.
//
// ...


?>


The idea is basically the same regardless of which programming language you choose. The lesson to be learned here? Always trim your data!

0 Comments:

Post a Comment

Feel free to write any comments or ideas!