Correspondence Between Cartier Divisor and Weil Divisor (Hartshorne Proposition 6.11, Chapter 2) Hartshorne gives a correspondence between Cartier divisors of X and Weil Divisors of X, when X is integral separated locally factorial noetherian scheme.
I understand given a Cartier Divisor how to define a Weil Divisor. 
But I don't understand the the other way correspondence. 
I have seen a proof of how a Weil Divisor D induces a Weil Divisor $D_x$ om the local scheme Spec$\mathcal O_x$ in Restricting a Weil divisor to a local scheme. And $D_x$ is a principal divisor. But I don't understand after that. 
Can someone please help
Thanks in advance. 
 A: Let's understand the subsequent arguments of the proof in steps. I will use the notation in your link's answer (, in which $T_x = \mathrm{Spec}\mathcal{O}_x$, and $X^{(1)}$ is the set of 1-codimensional points of $X$).

  
*
  
*The principal divisor $(f_x)$ on $X$ has the same restriction to $\mathrm{Spec}\mathcal{O}_x$ as $D$, hence they differ only at prime divisors which do not pass through $x$.
  

Recall that $D_x=\sum_{y\in X^{(1)}\cap T_x}n_y\cdot(\overline{\{y\}} \cap T_x)$, and that as a principal divisor in the $X$, $(f_x)=\sum_{y\in X^{(1)}}v_y(f_x)\cdot \overline{\{y\}}$, where $v_y$ is the valuation on the prime divisor $\overline{\{y\}}$.
Then note that the valuation of $\overline{\{y\}}$ is just the valuation of $\overline{\{y\}}\cap T_x$, since they have the same local rings on $y$. Thus the restrictions of $D_x$ and $(f_x)$ are both equal to $\sum_{y\in X^{(1)}\cap T_x}v_y(f_x)\cdot(\overline{\{y\}}\cap T_x)$, and globally they differ just at those points not in the $T_x$. But it's clear that a prime divisor doesn't pass through $x$, if and only if its generic point is not in the $T_x$.


  
*There are only finitely many of these which have a non-zero coefficient in $D$ or $(f_x)$, so there is an open neighbourhood $U_x$ of $x$ such that $D$ and $(f_x)$ have the same restriction to $U_x$.
  

That's really clear because $T_x$ is just the intersection of all open neighbourhoods of $x$, and replacing $T_x$ by a neighbourhood $U_x$ won't change the coefficients in both divisors.


  
*Covering $X$ with such open sets $U_x$, the functions $f_x$ give a Cartier divisor on $X$. Note that if $f$,$f'$ give the same Weil divisor on an open set $U$, then $f/f'\in\Gamma(U,\mathcal{O}^*)$, since $X$ is normal.
  

The second sentence needs to be verified. $(f)=(f')$ implies that $(f/f')=0$, whence in each $y\in X^{(1)}$, $f/f'$ is a unit of $\mathcal{O}_y$. For every affine open subset of $X$, say $\mathrm{Spec}A$, I claim that $f/f'$ is a global section on it, i.e. $f/f'\in A$. Indeed, each prime ideal $\mathfrak{p}$ of $A$, of height $1$, corresponds to a point of codimension $1$ in $X$, and thus $f/f'\in A_\mathfrak{p}$. Since $A$ is a normal noetherian domain, by commutative-algebra theories, we have
$$A=\bigcap_{\mathrm{ht}\mathfrak{p}=1}A_\mathfrak{p}.$$
Therefore $f/f'\in A$. Then given an affine open covering $\{U_i\}$ of $U$, $(f/f')|_{U_i}\in\Gamma(U_i,\mathcal{O})$, so one can glue them into a section in $\Gamma(U,\mathcal{O})$. Actually this section is just $f/f'$ because they must be the same in $\mathscr{K}$. Thus $f/f'\in\Gamma(U,\mathcal{O})$. Similarly, $f'/f$ is also in the $\Gamma(U,\mathcal{O})$. So we have $f/f'\in\Gamma(U,\mathcal{O}^*)$.
A: The point is that in a factorial domain, the height one prime ideals are principal. 
By definition a Weil divisor gives a height one prime ideal in the local ring a each point (this is the ideal that cuts out the Weil divisor), and if this local ring is factorial, it is principal, so we get an equation that cuts out the Weil divisor in a n.h. of this point.  And a divisor cut out by a single equation is precisely a Cartier divisor. 
