Relationships between X-ray photoelectron spectra, structure and superconductivity in LnBa2Cu3O7-x