Much depends on what you are already familiar with. If itβs more convenient for you to move XML documents using the Document Object Model, then XML::DOM , XML::LibXML or XML::Twig are good, and XML::TreeBuilder is a similar module that has its own API, and you will find Does it suit you only by tasting it.
However, all of these modules are designed to navigate and access existing XML data, and they are only partially useful for creating new XML from scratch. Instead, the XML::Generator , XML::Writer and XML::API modules are specifically designed for this purpose, and they all share the same interfaces. My preferences and my recommendation to you is XML::API , which has the most flexible interface and should fit your purpose well.
Using XML::API , the code for creating this XML document has a one-to-one correspondence with the resulting XML. Each statement corresponds to one XML element or tag, and tag and attribute names and text values ββcan be inferred from the run time, for example, using information from the database.
This program recreates your XML sample. Note that subsections can be separately encoded and subprogrammed by passing an XML::API object to each of them. It is also possible to generate XML non-linearly, since each method returns a link to the element that is being created, and there is a _goto method that accepts such a link and sets the location of subsequent additions. Indeed, instead of writing any data, the _close method simply executes _goto parent of the current element.
use strict; use warnings; use XML::API; my $xml = XML::API->new(doctype => 'xhtml'); $xml->_open('TumorDetails'); $xml->_element('personUpi', 'String'); $xml->_element('ageAtDiagnosis', '3.14159E0'); $xml->_element('biopsyPathologyReportSummary', 'String'); $xml->_open('primarySiteCollection'); $xml->_open('tissueSite'); $xml->_element('description', 'String'); $xml->_element('name', 'String'); $xml->_close('tissueSite'); $xml->_close('primarySiteCollection'); $xml->_open('distantMetastasisSite'); $xml->_element('description', 'String'); $xml->_element('name', 'String'); $xml->_close('distantMetastasisSite'); $xml->_open('siteGroup'); $xml->_element('description', 'String'); $xml->_element('name', 'String'); $xml->_close('siteGroup'); $xml->_open('tmStaging'); $xml->_element('clinicalDescriptor', 'String'); $xml->_element('clinicalMStage', 'String'); $xml->_open('siteGroupEdition5'); $xml->_element('description', 'String'); $xml->_element('name', 'String'); $xml->_close('siteGroupEdition5'); $xml->_open('siteGroupEdition6'); $xml->_element('description', 'String'); $xml->_element('name', 'String'); $xml->_close('siteGroupEdition6'); $xml->_close('tmStaging'); $xml->_open('pediatricStaging'); $xml->_element('doneBy', 'String'); $xml->_element('group', 'String'); $xml->_close('pediatricStaging'); $xml->_open('histologicTypeCollection'); $xml->_open('histologicType'); $xml->_element('description', 'String'); $xml->_element('system', 'String'); $xml->_element('value', 'String'); $xml->_close('histologicType'); $xml->_close('histologicTypeCollection'); $xml->_open('histologicGradeCollection'); $xml->_open('histologicGrade'); $xml->_element('gradeOrDifferentiation', 'String'); $xml->_close('histologicGrade'); $xml->_close('histologicGradeCollection'); $xml->_open('familyHistoryCollection'); $xml->_open('familyHistory'); $xml->_element('otherCancerDiagnosed', 'String'); $xml->_element('sameCancerDiagnosed', 'String'); $xml->_close('familyHistory'); $xml->_close('familyHistoryCollection'); $xml->_open('comorbidityOrComplicationCollection'); $xml->_open('comorbidityOrComplication'); $xml->_element('value', 'String'); $xml->_close('comorbidityOrComplication'); $xml->_close('comorbidityOrComplicationCollection'); $xml->_open('tumorBiomarkerTest'); $xml->_element('her2NeuDerived', 'String'); $xml->_element('her2NeuFish', 'String'); $xml->_close('tumorBiomarkerTest'); $xml->_open('patientHistoryCollection'); $xml->_open('patientHistory'); $xml->_element('cancerSite', 'String'); $xml->_element('sequence', '2147483647'); $xml->_close('patientHistory'); $xml->_close('patientHistoryCollection'); $xml->_open('tumorHistory'); $xml->_element('cancerStatus', 'String'); $xml->_element('cancerStatusFollowUpDate', '1967-08-13'); $xml->_element('cancerStatusFollowUpType', 'String'); $xml->_element('qualityOfSurvival', 'String'); $xml->_close('tumorHistory'); $xml->_open('placeOfDiagnosis'); $xml->_element('initials', 'String'); $xml->_close('placeOfDiagnosis'); $xml->_open('followUp'); $xml->_element('dateFollowUpChanged', 'String'); $xml->_element('dateOfLastCancerStatus', '1967-08-13'); $xml->_open('nextFollowUpHospital'); $xml->_element('initials', 'String'); $xml->_close('nextFollowUpHospital'); $xml->_open('lastFollowUpHospital'); $xml->_element('initials', 'String'); $xml->_close('lastFollowUpHospital'); $xml->_open('tumorFollowUpBiomarkerTest'); $xml->_element('her2NeuDerived', 'String'); $xml->_element('her2NeuFish', 'String'); $xml->_close('tumorFollowUpBiomarkerTest'); $xml->_close('followUp'); $xml->_close('TumorDetails'); print $xml;