subroutine ps_DumpToPSMLFile(ps,fname,indent)
use xmlf90_wxml
type(ps_t), intent(in) :: ps
character(len=*), intent(in) :: fname
logical, intent(in), optional :: indent
type(xmlf_t) :: xf
call xml_OpenFile(trim(fname),xf, indent)
call xml_AddXMLDeclaration(xf,"UTF-8")
call xml_NewElement(xf,"psml")
call my_add_attribute(xf,"version",trim(ps%version))
call my_add_attribute(xf,"energy_unit",trim(ps%energy_unit))
call my_add_attribute(xf,"length_unit",trim(ps%length_unit))
call my_add_attribute(xf,"uuid",ps%uuid)
call my_add_attribute(xf,"xmlns",ps%namespace)
! No top-level annotations in V1.1
! call dump_annotation(xf,ps%annotation)
call dump_provenance(xf,ps%provenance)
call dump_pseudo_atom_spec(xf,ps)
if (initialized(ps%global_grid)) then
call dump_grid(xf,ps%global_grid)
endif
call dump_valence_charge(xf,ps%valence_charge,ps%global_grid)
if (trim(ps%header%core_corrections) == "yes") then
call dump_core_charge(xf,ps%core_charge,ps%global_grid)
endif
if (trim(ps%header%meta_gga) == "yes") then
call dump_valence_kinetic_energy_density(xf,ps%valence_kinetic_energy_density,ps%global_grid)
if (trim(ps%header%core_corrections) == "yes") then
call dump_core_kinetic_energy_density(xf,ps%core_kinetic_energy_density,ps%global_grid)
endif
endif
call dump_semilocal_potentials(xf,ps)
call dump_local_potential(xf,ps)
call dump_nonlocal_projectors(xf,ps)
call dump_pseudo_wavefunctions(xf,ps)
call xml_EndElement(xf,"psml")
call xml_Close(xf)
end subroutine ps_DumpToPSMLFile