The integral of a square-integrable non-negative function equals zero implies function is zero a.e 
Let $\;f:(a,b)\rightarrow \mathbb R^n\;$ such that $\;f\in
 W^{1,2}_{loc} (a,b)\;$ and $\;g:\mathbb R^n \rightarrow [0,+\infty)\;$
  be a continuous function and suppose:
$\;\int_{x_0}^{x_1} \frac {{f'}^2(x)}{2}+g(f(x))\;dx=0\;\;\forall
 x_0,x_1:\;a\lt x_0 \lt x_1 \lt b\;$
Then $\; \frac {{f'}^2(x)}{2}+g(f(x))=0\;\;\;a.e\;$ in $(a,b)\;$

I know that since $\;f\in W^{1,2}_{loc} (a,b) \Rightarrow f,f'\in L^2_{loc} (a,b)\;$ . Searching here I came across with this post Showing that $f = 0 $ a.e. if for any measurable set $E$, $\int_E f = 0$ and I was wondering if there is any connection between that and my question.To be honest, I believe it does but I miss the key points as it seems.
I'm new to $\;L^p\;$ and measure theory so I apologize in advance if my question is trivial. I'm having a really hard time understanding how do we result in the "almost everywhere" statement from the above integral.
Any help would be valuable! Thanks
 A: All you need is the following: 

Let $h\colon (a,b)\to\mathbb R$ be a function such that for any $a\lt x_0\lt x_1\lt b$, $\int_{(x_0,x_1)} h(x)\mathrm dx=0$. Then $h=0$ almost everywhere.

As you pointed out, if we manage to show that 
$$\tag{*}   \int_{B} h(x)\mathrm dx=0$$
for each Borel subset of $(a,b)$, then we reach the wanted conclusion. The assumption give only (*) for interval. 


*

*This can be trivially extended to finite union of disjoint intervals.

*Using the dominated convergence theorem, we can see that (*) holds for countable unions of disjoint intervals. 

*An open subset of $(a,b)$ can be written as a disjoint union of intervals, hence (*) holds for any open subset of $(a,b)$. 

*Now, in order to extend (*) to each Borel subset of $(a,b)$, we need the following facts: 


*

*if $A\subset (a,b)$ is a Borel set, then for each positive $\delta$,   there exists an open set $O\supset A $ such that the Lebesgue measure of $O\setminus A$ is smaller than $\delta$;

*for each positive $\varepsilon$, there exists $\delta$ such that if $S$ is a set of measure smaller than $\delta$ then $\int_S\left\lvert h(x)\right\rvert\mathrm dx\lt \varepsilon$.            


