If you want to go the "chopped up" route, first start with the discrete sum (ignoring the total mass term for now)
$$\sum_{i=1}^Nx_im$$
where $x_i$ is the center of section $i$. This is an important term to have here, as we will see. By the set up, $x_i=(i-1/2)\Delta x$, so we have
\begin{align}
\bar x&\propto \sum_{i=1}^Nm\left(i-\frac12\right)\Delta x\\
&=m\Delta x\sum_{i=1}^N\left(i-\frac12\right)\\
&=m\Delta x\left(\frac{N(N+1)-N}{2}\right)\\
&=m\Delta x\left(\frac{N^2}{2}\right)
\end{align}
Now, the total mass is given by $Nm$, and $\Delta x=X/N$, so we end up with
$$\bar x=\left(m\cdot\frac XN\cdot\frac{N^2}{2}\right)/(Nm)=X/2$$ with no integral needed.
However, I did this to point out how important the position of each mass is. In your integral where you just do $m\,\text dx$ you have completely removed all information about the position of each mass, because $\text dx$ is not the position of each mass element, just like how $\Delta x$ in the above example wasn't the position $x_i$ of each section, it would be like instead starting with the sum $\sum_{i=1}^N m\Delta x$, which doesn't tell you where any mass is.
The $\Delta x$ or $\text dx$ is instead used to determine the location of each mass element. You can't just switch the integration variable without realizing this. This is why you need to specify some linear mass density function $\lambda(x)=\frac{\text dm}{\text dx}$ that can be used to indicate how much mass is located at each position as you do the integral over space. i.e. for the mass element at position $x$, $\lambda(x)\text dx=\text dm$ amount of mass is present, so then $x\,\text dm=x\lambda (x)\,\text dx\neq m\,\text dx$
In the discrete example with the uniform rod, $\lambda=M/X=Nm/X=m/\Delta x$. So to come full circle our sum of interest would have been
$$\sum_{i=1}^Nx_i\lambda\Delta x$$
And so there is your full analogy
$$\sum_{i=1}^Nx_im=\sum_{i=1}^Nx_i\lambda\Delta x$$
$$\int x\,\text dm=\int x\lambda\,\text dx$$
Also note that this is true for any change of variables. You cannot just exchange $m$ variables for $x$ variables and vice versa. You have to keep in mind how one variable varies with respect to the other. For example, in the usual "u-substitution" method taught in most introductory calculus classes, you have some proposed substitution $u=f(x)$, and so your differentials are related by $\text du=\frac{\text df}{\text dx}\text dx$.