We adapt our recently developed constraint-based orbital-optimized excited-state method (COOX) for the computation of core excitations. COOX is a constrained density functional theory (cDFT) approach based on excitation amplitudes from linear-response time-dependent DFT (LR-TDDFT), and has been shown to provide accurate excitation energies and excited-state properties for valence excitations within a spin-restricted formalism. To extend COOX to core-excited states, we introduce a spin-unrestricted variant which allows us to obtain orbital-optimized core excitations with a single constraint. Using a triplet purification scheme in combination with the constrained unrestricted Hartree-Fock formalism, scalar-relativistic zero-order regular approximation corrections, and a semiempirical treatment of spin-orbit coupling, COOX is shown to produce highly accurate results for K- and L-edge excitations of second- and third-period atoms with subelectronvolt errors despite being based on LR-TDDFT, for which core excitations pose a well-known challenge. L- and M-edge excitations of heavier atoms up to uranium are also computationally feasible and numerically stable, but may require more advanced treatment of relativistic effects. Furthermore, COOX is shown to perform on par with or better than the popular ΔSCF approach while exhibiting more robust convergence, highlighting it as a promising tool for inexpensive and accurate simulations of X-ray absorption spectra.