How to locate and display a file

xdg-open doesn't read from stdin. Use

locate X | xargs -L1  xdg-open

You need to use:

xdg-open "$(locate X)"

If your file contains spaces/special characters you need to use:

xdg-open "$(locate "X")"

Note: This command must be directly used in terminal. Use of this command in shell scripting need to be avoided as it may generate errors or inconsistent outputs.