At these words the Princess burst into tears , and when the King saw this he ordered her to be shut up in a high tower and carefully guarded till the dangerous magician should either have left the kingdom or been hung on the nearest tree .