We demonstrate the application of a new method of analytical transmission electron microscopy for measuring very accurately small amounts of solute atoms within a well-defined planar defect such as a stacking fault, grain boundary or an interface. The method is based on acquiring several spectra with different electron beam diameters from the same position centred on the defect. It can be applied to energy-dispersive X-ray microanalysis (EDXS) or electron energy-loss spectroscopy (EELS) and does not necessitate a scanning unit. The accuracy has been tested numerically under different conditions using simulations for a specific geometry and has been found to be substantially better than that of any other current standard technique. Our calculations suggest an extremely high accuracy theoretically achievable in the determination of e.g. the Gibbsian solute excess or the doping level of a grain boundary down to about ±1% of an effective monolayer, i.e. ±0.1 atoms/nm2 under typical experimental conditions. The method has been applied to zinc oxide, which forms inversion domain boundaries (IDBs) when doped with different transition metal oxides such as SnO2 or Sb2O3. We obtained an experimental precision of ±0.4 atoms/nm2, which has allowed us to solve the atomic structure of the IDBs.