Context. The eclipsing low-mass X-ray binary X1822-371 is the prototype of the accretion disc corona (ADC) sources. Its inclination angle ( 82.5 • ) is high enough that flux from the neutron star is blocked by the edge-on accretion disc. Because the neutron star's direct emission is hidden, its ADC emission is visible. The physical properties of the ADC in X1822-371 have been widely studied, but are still debated in literature. In light of the recent literature and of the results reported in this work we show that the ADC is optically thin. Aims. We analyse two Chandra observations and one XMM-Newton observation to study the discrete features in this source and their variation as a function of the orbital phase, deriving constraints on the temperature, density, and location of the plasma responsible for emission lines. Methods. The HETGS and XMM/Epic-pn observed X1822-371 for 140 and 50 ks, respectively. We extracted an averaged spectrum and five spectra from five selected orbital-phase intervals that are 0.04-0.25, 0.25-0.50, 0.50-0.75, 0.75-0.95, and, finally, 0.95-1.04; the orbital phase zero corresponds to the eclipse time. All spectra cover the energy band between 0.35 and 12 keV. Results. We confirm the presence of local neutral matter that partially covers the X-ray emitting region; the equivalent hydrogen column is 5 × 10 22 cm −2 and the covered fraction is about 60-65%. We identify several emission lines of He-like and H-like ions, and a prominent fluorescence iron line associated with a blending of Fe i-Fe xv resonant transitions. The transitions of He-like ions show that the intercombination dominates over the forbidden and resonance lines. The line fluxes are the highest during the orbital phases between 0.04 and 0.75. Conclusions. We discuss the presence of an extended, optically thin corona with optical depth of about 0.01 that scatters the X-ray photons from the innermost region into the line of sight. The photoionised plasma producing the O viii, Ne ix, Ne x, Mg xi, Mg xii, Si xiii, and Si xiv lines is placed in the bulge at the outer radius of the disc distant from the central source of 6 × 10 10 cm. The O vii and the fluorescence iron line are probably produced in the photoionised surface of the disc at inner radii. Finally, we suggest that the observed local neutral matter is the matter transferred by the companion star that was expelled from the system by the X-ray radiation pressure, which in turn originated in the accretion process onto the neutron star.