Approximately 15% of cancers worldwide are believed to be caused by viral infections. Some of the viruses that can increase the risk of cancer include human papillomavirus, hepatitis B and C viruses, Epstein-Barr virus, and human immunodeficiency virus. Recent advancements in sequencing technologies have made it possible to collect large amounts of tumor DNA data for computational analysis, allowing researchers to study the potential association between cancers and viral pathogens. However, the diverse nature of oncoviral families makes it challenging to reliably detect viral DNA, making such analysis difficult. This paper introduces XVir, a data pipeline that uses a transformer-based deep learning architecture to accurately identify viral DNA in human tumors. XVir is trained on genomic sequencing reads from viral and human genomes and can be used with tumor sequence information to detect viral DNA in human cancers. Results from semi-experimental data show that XVir achieves high detection accuracy, often outperforming existing methods while being more compact and computationally efficient.