Really, experience points are just a game mechanic, used to incentivize and/or reward certain behaviors
As noted in the passage you quoted, they are meant as rough indicators of the experiences that help a character learn, grow, and improve herself...but any close mapping to how real people learn and grow is tenuous at best.
Would apprenticing with a high level wizard help you master new spells as quickly as shooting orcs with magic missiles day after day? Perhaps, but it wouldn't make for an interesting game incentive.
Some GMs assign XP only (or primarily) for defeating monsters. Others use them to reward clever solutions to problems and/or great roleplaying. In either case, looking too closely reveals that XP are really just a means to incentivize and/or reward certain behaviors.
Pathfinder without XP
As a side note, at least half the Pathfinder (and other 3.x) games I play nowadays don't actually use them; the party just levels up when it fits the story.
In general, I'm a fan of doing away with XP in Pathfinder, but there are downsides to doing so. The main advantages I see of using XP versus simply leveling by GM fiat are:
- XP provides visability which some players will appreciate (e.g. I've accumulated 4226 of the 5000 XP I need to get to the next level), and
- Assigning XP values by the book may avoid arguments with players who think they should certainly have levelled up by now.
How about a permanented (or maybe, immovable because it is activated by something too large to move, like an obelisk) Mordenkainen's Magnificent Mansion (PHB p256, Mage's Magnificent Mansion in SRD)? It's a 7th level spell, it is nearly perfectly safe (it can be entered only through ONE portal, which only opens at caster's will). It's a perfect lodge, and if you bind it to the place, it becomes a great safehouse...
Which can be destroyed by Mordenkainen's Disjunction (PHB p255, Mage's Disjunction in SRD), a 9th level spell which automatically dispells all the magic in the area, makes every magic item to make a Will save or be turned into a mundane item and even has a chance of destroying artifacts. The key here is to make sure that all the PC and their gear are at the other side of the Mansion and the demons do not know about that, which will guarantee that nobody would loose any important magic items.
So, in short: Place a statue/obelisk/something else too large to move (or known to lose its power if moved) in the city, let the party activate it to grant them lodging, access to a treasury and the other things you think they need, and let them enjoy that large house for a while. Perhaps it is even activated and deactivated by a treasure the party removed from the dungeon, providing them with a key to the mansion. Then, when you think the time is right, dispel it with Mordekainen's Disjunction (which would be even more surprising if the house had successfully resisted some really hard hits) and let the players suddenly face that high-level encounter 8)
Best Answer
There are online encounter calculators that do the work for you. The actual number of CR-appropriate encounters necessary to level up is 13.3.