I'm trying to prove the following:
If $X=\text{Spec}(A)$ where $A$ is a domain, then $\mathcal{O}_X(U)=\bigcap_{p\in U}A_p$ for any open $U\subset X$.
In the special case when $U$ is principal open set $X_f$, the claim is that $A_f=\bigcap_{p\in X_f}A_p$. The ring $B:=A_f$ is a domain and for every $p\in X_f$ we have isomorphisms $(A_f)_{pA_f}\simeq A_p$. By properties of primes in localizations, the claim amounts to: $$B=\bigcap_{q\in\text{Spec}(B)}B_q$$
which is a well-known result for domains.
Now for the general case $U=\bigcup_i X_{f_i}$, I don't know what to do. I only know the formal definition $$\mathcal{O}_X(U)=\varprojlim_{X_f\subset U}A_f$$
and I don't know how to relate this to $\bigcap_{p\in U}A_p$.
How should I approach this?
I think the quickest way to see this is as follows: The assignment $ \mathcal{R} $ which assigns to an open set $ U $ the ring $ \mathcal{R}(U) = \cap_{p \in U} A_p $ is clearly a sheaf and it agrees with the structure sheaf on the basic open sets $ \operatorname{Spec} A_f $. Since sheaves are uniquely determined by their values on a basis, $ \mathcal{R} = \mathcal{O}_X $.