Open subset associated to a global section of a scheme Let $U=\text{Spec}(A)$ be an open subset of a scheme $X$ and $f\in \Gamma(X,\mathcal{O}_X)$. We define $$X_f=\{x\in X: f_x\notin \mathfrak{m}_x\subseteq \mathcal{O}_x\}.$$
Then, we have to prove that $X_f$ is open in $X$. 
This is an exercise in Hartshone. It asks to prove that $X_f\cap U=D(\bar{f})$ where $\bar{f}=f|_U$.
Let $P\in U\cap X_f$ i.e., $P\in \text{Spec}$(A) and $f_P\notin \mathfrak{m}_P\subseteq \mathcal{O}_P$. I am stuck here and could not proceed. 
I tried when $X=U=\text{Spec}(A)$. Then, we have isomorphism $\mathcal{O}_P\rightarrow A_P$ given by $s:U\rightarrow \bigsqcup_{q\in U} A_q$ goes to $s(P)$.  Given $f\in \Gamma(X,\mathcal{O}_X)=A$ we have $f:U\rightarrow \bigsqcup_{q\in U} A_q$ given by $f(q)=\frac{f}{1}\in A_q$. Then, $f\in \mathcal{O}_X(U)$ as per the definition of structure sheaf on $\text{Spec}(A)$. So, the isomorphism sends $[f]$ to $f(P)=\frac{f}{1}\in A_P$ i.e., $f_p\in \mathcal{O}_P$ is identified with $\frac{f}{1}\in A_P$ and $\mathfrak{m}_P$  is identified with the maximal ideal $PA_P$. So, 
$$X_f=\{P\in X: f_P\notin \mathfrak{m}_P\subseteq \mathcal{O}_P\}
=\{P\in X:\frac{f}{1}\notin PA_P\}=\{P\in X:f\notin P\}=D(f).$$
Let me know if this justification is correct. Any suggestions regarding arbitrary schemes are welcome.
 A: I'll try and write out the logic explicitly for the general case where the scheme $X$ is covered by a collection of open affine subschemes $\{ U_i \}$ where each $U_i = {\rm Spec}(A_i)$ for some ring $A_i$.
We have natural restriction maps:
$$ \Gamma(X, \mathcal O_X) \to \Gamma(U_i, \mathcal O_X) \cong A_i.$$
Let's fix an $i$, and let's denote the image of $f$ under the above restriction map by $\bar {f_i}$, which we're thinking of as an element of the ring $A_i$. Any point $P \in U_i$ is represented by a prime ideal $\mathfrak p \subset A_i$, and the restriction of $f$ to the stalk $\mathcal O_P$ is represented by the element $$\frac{\bar {f_i}}{1} \in (A_i)_{\mathfrak p}.$$
[Remember, restricting a section to a stalk at a point is the same as restricting the section to an open subset containing the chosen point, and then restricting it further to the stalk at that point.]
By the argument you provided, the set $X_f \cap U_i$ is precisely the set $$ D(\bar{f_i}) = \{ \mathfrak p {\rm \ prime } \subset A_i : \bar{f_i} \notin \mathfrak p\},$$
which is open, by the definition of the Zariski topology. Since $X_f \cap U_i$ is open for every $U_i$ in the open cover, we may conclude that $X_f$ itself is open.
