I have residence ID in Ukraine (out of Schengen) and I want to travel from Beijing airport.
My flight has 6 hours connection in Stockholm.
Do I need a (transit) visa?
In Schengen area, in most airports (as far as I know, all airports you might transit through), there are distinct Schengen airport zone and an international zone.
As a general rule, you cross the border in/out of Schengen only if needed. If your origin and destination are both out of Schengen area, if you stay in the airport, you do not need to cross the border and therefore do not need a visa.
If you want to go to the city for a tourism break in your journey, you should check the country's exact policy regarding transit visa. Several offer such an option. For Stockholm, a question on this site handles the subject.
If your final destination is in Schengen area, you should cross the border at the first airport you fly in.