Sorbent material packed in a PTFE laboratory-made flow cell located in the specimen holder of an energy-dispersive X-ray fluorescence (EDXRF) detector has been used for in situ solid-phase extraction (SPE) preconcentration-detection of metals. The flow cell was connected to a single-channel flow-injection (FI) manifold (for full automation of the steps and proper development of the method) by two PTFE tubes of 0.5-mm inner diameter introduced into the spectrometer specimen holder by a small orifice without distortion or modification of the instrument. The optical window open in the PTFE flow cell was adjusted to the X-ray irradiation zone of the spectrometer and fixed to it. The approach was tested by using both Pb and Cd aqueous solutions and a Dowex 50 cation-exchange resin as a sorbent, and flushing the sample through the flow cell for EDXRF measurements after removal of the sample matrix. The limits of detection and the limits of quantification (LOQs) thus obtained were 0.15 and 0.5 microg for Pb and 0.3 and 0.8 microg for Cd, respectively, values that allow the approach to be used for the analysis of drinking water by injecting a 100-mL sample into the FI manifold, taking into account the EC drinking water directives. The linear dynamic ranges are between the LOQ and 600 microg for both analytes. The method was validated by the standard addition method using tap-water samples. In addition, the integrated SPE-EDXRF approach enables the study of the variables influencing the sorption step-namely the effects of the volume of sample flushed through the column, concentrations of the analytes in the sample, breakthrough volume of the resin, elution profiles, sample pH and retention and elution flow rates-in an automatic, cheap, fast and precise way.