Xanax, also known by its generic name alprazolam, is a poor choice for treatment of panic disorder and GAD. Xanax is classified as a benzodiazepine, and they work on GABA receptors, which serve to reduce the hyperactivity of anxiety circuits in anxiety disorders. Although Xanax is effective and fast acting on anxiety, it has the potential for abuse, so it's not an ideal choice of treatment. Also, Xanax has a short half-life, which requires multiple dosing throughout the day to get anxiety relief, often requiring dosing from 3 times daily to 4 times daily.
Also, on benzodiazepines, you can develop tolerance and dependence on it, so you may need ever increasing doses of Xanax to get the same effect, and you may become physically dependent on it. When you become dependent on it, then stopping or reducing the Xanax may induce withdrawal symptoms, and this may lead to more anxiety symptoms than you started out with.
There are better treatments for panic disorder and GAD, such as CBT (cognitive behavioral therapy), SSRIs (selective serotonin reuptake inhibitors), and SNRIs (serotonin norepinephrine reuptake inhibitors).