http://www.perlmonks.org?node_id=1230103

cciiaandrei has asked for the wisdom of the Perl Monks concerning the following question:

Hello. I want to create a PERL script to convert something like this into XML, with logical headers.

acc_BM: C:\work\workspace\ACC-8.6.0\TAM\plugins\BswM_TS_TxDxM1I14R0\sr +c\BswM.c, 31: warning: redundant redeclaration of 'Com_MainFunctionRx +' [-Wredundant-decls] (included from C:/work/workspace/ACG-8.6.0/TAM/ +plugins/Com_TS_TxDxM6I3R0/include/Com_Api_Static.h, line 1092) extern FUNC(void, COM_CODE) Com_MainFunctionRx ^~~~~~~~~~~~~~~~~~, TestSequences: SwInt_ +ConTest_TestInt_ATS_MODE_ECUM SwInt_ConTest_TestInt_ATS_MODE_RestartE +CUM acc_BC: C:\work\workspace\ACC-8.6.0\tests\Conformance\IN\SwInt_ConTest +_CS_Rte_SomeIpXf_Com_p0\output\generated\src\Com_Lcfg.c, 40: warning: + redundant redeclaration of 'Com_MainFunctionTx' [-Wredundant-decls] +(included from C:/work/workspace/ACG-8.6.0/TAM/plugins/Com_TS_TxDxM6I +3R0/include/Com_Api_Static.h, line 833) extern FUNC(void, COM_CODE) Com_MainFunctionTx ^~~~~~~~~~~~~~~~~~, TestSequences: SwInt_ +ConTest_CS_Rte_SomeIpXf_Com_p0

So the steps would be:

  1. To read all the .txt file(on all lines) that contains that data
  2. To create a blank abc.xml document
  3. To define the XML schema with tags like Module, Path, Warning, Test Sequence
  4. To populate with data the new created .xml file , so it should look like that:
<Warnings> <Module>acc_BM</Module> <Path>C:\work\workspace\ACC-8.6.0\TAM\plugins\BswM_TS_TxDxM1I14R0 +\src\BswM.c</Path> <warning>redundant redeclaration of 'Com_MainFunctionRx' [-Wredun +dant-decls] (included from C:/work/workspace/ACG- 8.6.0/TAM/plugins/Com_TS_TxDxM6I3R0/include/Com_Api_Static.h, li +ne 1092) extern FUNC(void, COM_CODE) Com_MainFunctionRx</warning> <TestSequence>SwInt_ConTest_TestInt_ATS_MODE_ECUM SwInt_ConTest_T +estInt_ATS_MODE_RestartECUM acc_BC: C:\work\workspace\ACC-8.6.0\tests\Conformance\IN\SwInt_C +onTest_CS_Rte_SomeIpXf_Com_p0\output\generated\src\Com_Lcfg.c</TestSe +quence> </Warnings>

It has to be smart, to be self adjust, because for example on test sequences, the names will vary, but will be like XXX.c

Replies are listed 'Best First'.
Re: text on multiple lines to XML using PERL
by Laurent_R (Canon) on Feb 18, 2019 at 14:34 UTC
    Please use markup to format your post: Markup in the Monastery

    Update: changed the link to the markup page, following Marto's comment below.