Why X-path is more preferred

Why do we prefer x-path as compared to others locators for finding element paths?

X-path works assuming that the path doesn’t change. In real time projects, the path changes when using a IDE to generate HTML page. IDE generates automated code and it alters the DOM structure quite frequently. This refactoring can be avoided to a certain extent by carefully choosing relative X-path and right locator.