How to integrate $ \int \frac{x^2}{(x \sin(x)+\cos(x))^2} \mathrm{d}x$ 
Evaluate
$$\displaystyle \int \frac{x^2}{(x \sin(x)+\cos(x))^2} \mathrm{d}x$$

Can someone just tell me the necessary manipulations? Hints will be enough.
Can it be done by integration by parts?
 A: First we use integration by parts, Let $$f(x)=x\sec x\text{ and } g(x)=\frac{x\cos x}{(x\sin x+\cos x)^2}$$ 
And as ac onsequence: $$G(x)=\frac{-1}{x\sin x+cosx} \text{ and }f'(x)=\sec x+x\sec x \tan x$$ and we have:
$$\begin{align}\int f(x)g(x)&= f(x)G(x)-\int f'(x)G(x)\\ \\
                            &=\frac{-x\sec x}{x\sin x +\cos x }+\int   \frac{\sec x+x\sec x\tan x}{x\sin x+\cos x}\\ \\
&=\frac{-x\sec x}{x\sin x +\cos x }+\int \sec^2 x\\ \\
&=\frac{-x}{\cos x(x\sin x +\cos x) }+\tan x\\ \\
&=\frac{-x+\sin^2 x(x \sin x+\cos x)}{\cos x(x\sin x +\cos x)} \end{align}$$
Answer : $$\frac{\sin(x)-x\cos(x)}{x\sin(x)+\cos(x)}+C$$
A: I've used a non-standard method.
1) note that the denominator in the integrand is a square, so I think that the primitive is a fraction (the derivative of a fraction has a square at denominator).
2) I search if there is a simple function that can be the numerator of the fraction, and I search from function of the form
$ \dfrac{ ax \sin x +b \cos x}{x\sin x + \cos x}$
or 
$ \dfrac{ax \cos x +b \sin x}{x\sin x + \cos x}$.
3) the first form does not work, since, deriving, at the numerator we have some $\sin $ and $\cos$ functions.
4) the second form work well. We have, for the numerator of the derived function:
$
(a \cos x-ax \sin x +b \cos x)(x \sin x + \cos x)-(\sin x+x \cos x -\sin x)(ax \cos x +b \sin x)
$
so, if $b=-a$ we have
$
-ax^2\sin x(x \sin x- \cos x)-x \cos x(ax \cos x-a\sin x)=-a(\sin^2 x + \cos^2 x)
$
and for $a=-1$ wh have a primitive:
$ \dfrac{-x \cos x + \sin x}{x\sin x + \cos x}$.
A: $\bf{My\; Solution::}$Given $$\displaystyle \int \frac{x^2}{\left(x \cdot \sin x+\cos x \right)^2}\mathrm{d}x$$
Now we can write $$\displaystyle x\cdot \sin x+1\cdot \cos x  = \sqrt{1+x^2}\cdot \left(\sin x\cdot \frac{x}{\sqrt{1+x^2}}+\cos x\cdot \frac{1}{\sqrt{1+x^2}}\right)$$
$$\displaystyle =\sqrt{1+x^2}\cdot \cos \left(x-\phi\right).$$
Where $\displaystyle \sin \phi = \frac{x}{\sqrt{1+x^2}}$ and $\displaystyle \cos \phi = \frac{1}{\sqrt{1+x^2}}$ and $\displaystyle \tan \phi = x\Rightarrow \phi = \tan^{-1}(x).$
So our Integral now becomes $$\displaystyle  = \int\frac{x^2}{1+x^2}\cdot \sec^2 (x-\phi)\mathrm{d}x$$.
Now Let $$(x-\tan^{-1}(x))=t\;,$$ Then $$\displaystyle \frac{x^2}{1+x^2}\mathrm{d}x = \mathrm{d}\phi.$$
So Integral Convert into $$\displaystyle \int \sec^2 t \ \mathrm{d}t  = \tan t +\mathcal{C} = \tan \left(x-\tan^{-1}(x)\right)+\mathcal{C}$$.
$$\displaystyle = \frac{\tan x-x}{1+x\cdot \tan x}+\mathcal{C}=\frac{\sin x-x \cdot \cos x}{\cos x+x\cdot \sin x}+\mathcal{C}$$
So $$\displaystyle \int \frac{x^2}{(x\sin x+\cos x)^2}\mathrm{d}x = \frac{\sin x-x \cdot \cos x}{\cos x+x\cdot \sin x}+\mathcal{C}$$
