in reply to Re: XML Parsing in a "mixed content" file
in thread XML Parsing in a "mixed content" file

Hi Marto, the source data is XML with TT instructions in the file.

The XML is intended to create and XLS file.Below is an extract

<?xml version="1.0" encoding="ISO-8859-1"?> <workbook> <worksheet name="[% config.template %]"><format color="black"> [% FOREACH host IN hosts %] <row><bold><format color="white" size="14" bg_color="blue"><cell w +idth="60" text="Configuring de : [% host.name %]" /></format></bold>< +/row> <row /> [% FOREACH int IN host.interfaces %] <row><cell text="interface ip-bundle [% int.bundle %].[% int.subBu +ndle %]" /></row> [% FOREACH ip IN int.secondaries %] <row><cell text=" ip address [% ip.ipAddress %] [% ip.subnetMask % +] [% bits(ip.ipAddress,ip.subnetMask) %] secondary" /></row> [% END %] <row><cell text="!"/></row> [% END %] <row /> <row><bold><format color="white" size="14" bg_color="blue"><cell t +ext="END OF : [% host.name %]" /></format></bold></row> <row /><row /><row /> [% END %] </format> </worksheet> </workbook>
So what I want to do, is extract both "cell text" and TT instructions to recreate the content in HTML format. Problem is, how should I parse the file so that I can retrieve XML with XML::LibXML & TT instruction lines at the same time ? Like I said, my objective is to display the template to the users. Creating the XLS file is not a problem. I want to show network engineers how the template is built without giving access to the .tt file.

Replies are listed 'Best First'.
Re^3: XML Parsing in a "mixed content" file
by marto (Cardinal) on Jan 11, 2019 at 16:53 UTC

    "the source data is XML with TT instructions in the file."

    That's not really the source data, since you need to create the XML. Your solution creates an XML file using Templates, I was asking what the source data was, since you obviously have it in a perl script, you could use this data to feed both the preview (one method described above) and create the Spreadsheet (Excel::Writer::XLSX). Seems illogical to create a file in a certain format only to parse it back into perl just to present a preview.

      I think I'm being misunderstood. I want to show how the template is built ( showing the whole logic) without dealing with all the xml tags in that view. So I need to extract TT instructions + cell text values. Makes sense ? Luc