You need to have the entire SLD/TLD database to do this. There's no other general purpose way, especially because there's in some edge cases third or fourth level domains.
X is not a known protocol. Presumably you want file
Is your map tiled? If so, the labels might be disappearing because they cross the tile boundaries (as the code cannot reliably predict if the other part of the label will show up in the nearby tile).