Interesting integral $\int_{0}^{\frac{\pi}{4}} \frac{x^{2}}{(x \sin x+\cos x)^{2}} d x$? Noting that
$\displaystyle d(x \sin x+\cos x)=x \cos xdx,\tag*{} $
we have
$\displaystyle \int_{0}^{\frac{\pi}{4}} \frac{x^{2}}{(x \sin x+\cos x)^{2}} d x=-\int_{0}^{\frac{\pi}{4}} \frac{x}{\cos x} d\left(\frac{1}{x \sin x+\cos x}\right)\tag*{} $
Integration by parts gives
$\displaystyle \begin{aligned}I &=-\left[\frac{x}{\cos x(x \sin x+\cos x)}\right]_{0}^{\frac{\pi}{4}}+\int_{0}^{\frac{\pi}{4}} \frac{\cos x+x \sin x}{\cos ^{2} x} \cdot \frac{1}{x \sin x+\cos x} d x \\&=-\frac{\frac{\pi}{4}}{\frac{1}{\sqrt{2}}\left(\frac{\pi}{4} \cdot \frac{1}{\sqrt{2}}+\frac{1}{\sqrt{2}}\right)}+\int_{0}^{\frac{\pi}{4}} \sec ^{2} x d x \\&=-\frac{2 \pi}{\pi+4}+[\tan x]_{0}^{\frac{\pi}{4}} \\&=\frac{4-\pi}{4+\pi}\end{aligned}\tag*{} $
Is there any other method?
 A: Well, we are trying to solve:
$$\mathcal{I}\left(x\right):=\int\underbrace{\left(\frac{x}{x\sin\left(x\right)+\cos\left(x\right)}\right)^2}_{:=\space\mathscr{I}\left(x\right)}\space\text{d}x\tag1$$
Rewrite the integrand using $\sin^2\left(x\right)+\cos^2\left(x\right)=1$:
$$\mathscr{I}\left(x\right)=\left(\frac{x}{x\sin\left(x\right)+\cos\left(x\right)}\right)^2=\frac{x^2\sin^2\left(x\right)+x^2\cos^2\left(x\right)}{\left(x\sin\left(x\right)+\cos\left(x\right)\right)^2}\tag2$$
Look to cancel terms with the denominator by adding and subtracting a term from the numerator:
$$\mathscr{I}\left(x\right)=\frac{x^2\sin^2\left(x\right)+x^2\cos^2\left(x\right)}{\left(x\sin\left(x\right)+\cos\left(x\right)\right)^2}=$$
$$\frac{x^2\cos^2\left(x\right)-x\sin\left(x\right)\cos\left(x\right)}{\left(x\sin\left(x\right)+\cos\left(x\right)\right)^2}+\frac{x^2\sin^2\left(x\right)+x\sin\left(x\right)\cos\left(x\right)}{\left(x\sin\left(x\right)+\cos\left(x\right)\right)^2}\tag3$$
Factor and cancel terms:
$$\mathscr{I}\left(x\right)=\frac{x\cos\left(x\right)\left(x\cos\left(x\right)-\sin\left(x\right)\right)}{\left(x\sin\left(x\right)+\cos\left(x\right)\right)^2}+\frac{x\sin\left(x\right)}{x\sin\left(x\right)+\cos\left(x\right)}\tag4$$
Integrate the sum term by term:
$$\mathcal{I}\left(x\right)=\int\frac{x\cos\left(x\right)\left(x\cos\left(x\right)-\sin\left(x\right)\right)}{\left(x\sin\left(x\right)+\cos\left(x\right)\right)^2}\space\text{d}x+\int\frac{x\sin\left(x\right)}{x\sin\left(x\right)+\cos\left(x\right)}\space\text{d}x\tag5$$
Using IBP: $\int\text{f}\space\text{dg}=\text{fg}-\int\text{g}\space\text{df}$, where $f=\sin\left(x\right)-x\cos\left(x\right)$, $\text{dg}=-\frac{x\cos\left(x\right)}{\left(x\sin\left(x\right)+\cos\left(x\right)\right)^2}\space\text{d}x$, $\text{g}=\frac{1}{x\sin\left(x\right)+\cos\left(x\right)}$ and $\text{df}=x\sin\left(x\right)\space\text{d}x$. This leads to:
$$\mathcal{I}\left(x\right)=\frac{\sin\left(x\right)-x\cos\left(x\right)}{\cos\left(x\right)+x\sin\left(x\right)}\underbrace{-\int\frac{x\sin\left(x\right)}{x\sin\left(x\right)+\cos\left(x\right)}\space\text{d}x+\int\frac{x\sin\left(x\right)}{x\sin\left(x\right)+\cos\left(x\right)}\space\text{d}x}_{=\space0}\tag6$$
So, we end up with:
$$\mathcal{I}\left(x\right)=\frac{\sin\left(x\right)-x\cos\left(x\right)}{\cos\left(x\right)+x\sin\left(x\right)}+\text{C}\tag7$$

So, your definite integral gives:
$$\mathcal{I}\left(\frac{\pi}{4}\right)-\mathcal{I}\left(0\right)=\frac{8}{4+\pi}-1-0=\frac{8}{4+\pi}-1=\frac{4-\pi}{4+\pi}\tag8$$
A: \begin{align}
&\int_{0}^{\frac{\pi}{4}} \frac{x^{2}}{(x \sin x+\cos x)^{2}} d x\\
=& \int_{0}^{\frac{\pi}{4}} \frac{x^{2}\sec^2x}{(1+x \tan x)^{2}} d x
= \int_{0}^{\frac{\pi}{4}}
\frac{1}{(1+x \tan x)^{2}}+ \frac{x^{2}\sec^2x -1}{(1+x \tan x)^{2}} \ d x\\
=& \ \left( \frac1{x+\cot x} - \frac{x}{1+x\tan x}\right)_0^{\frac\pi4}= \frac{4-\pi}{4+\pi}
\end{align}
