check if the document exists  before parsing