Constructing a class of topological solitons in magnetohydrodynamics