We present a generator-coordinate method for realistic shell-model Hamiltonians that closely approximates the full shell model calculations of the matrix elements for the neutrinoless double-β decay of Sn124, Te130, and Xe136. We treat not only quadrupole deformations but also the proton-neutron pairing amplitudes as generator coordinates. We validate this method by calculating and comparing spectroscopic quantities with the exact shell model results and experimental data. Our Hamiltonian-based generator-coordinate method produces 0νββ matrix elements much closer to the shell model ones, compared to the existing energy-density-functional-based generator-coordinate approaches. The remaining overestimation of 0νββ nuclear matrix element suggests that additional correlations may be needed to be taken into account for Sn124, Te130, and Xe136 when calculating with the Hamiltonian-based generator-coordinate method. The validation of this method may open the possibility of calculating 0νββ matrix element of Nd150 in a large shell-model space.