import groovy.xml.MarkupBuilder
import groovy.xml.StreamingMarkupBuilder
import groovy.xml.XmlUtil
import javax.xml.ws.Response
import groovy.xml.*
class ParsingXML {
static main (args) {
/*
Parsing the XML as text using XmlSlurper class
*/
def xmlInput = new XmlSlurper().parseText('''<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_GraosSAP_Resp xmlns:ns0="http://RocheCoeMetting">
<ResponseBlocoGraos>
<BlocoFI>
<Code>01</Code>
<Description>Test Material Description</Description>
</BlocoFI>
<BlocoMM>
<Code>007</Code>
<Description>Test Finance Description></Description>
</BlocoMM>
<BlocoNFe>
<MensagemError>1</MensagemError>
<NroComprovanteSAP>1</NroComprovanteSAP>
<NroComprovanteSPET>1</NroComprovanteSPET>
<OK>Success</OK>
<StringXMLNFe><![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<nfeProc versao="3.10" xmlns="http://www.portalfiscal.inf.br/nfe">
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
<infNFe Id="NFe35150300822602000124550010009923461099234656" versao="3.10">
<ide>
<cUF>35</cUF>
<cNF>09923465</cNF>
<natOp>Venda prod. do estab.</natOp>
<indPag>1</indPag>
<mod>55</mod>
<serie>1</serie>
<nNF>992346</nNF>
<dhEmi>2015-03-27T09:40:00-03:00</dhEmi>
<dhSaiEnt>2015-03-27T09:40:00-03:00</dhSaiEnt>
<tpNF>1</tpNF>
<idDest>1</idDest>
<cMunFG>3550308</cMunFG>
<tpImp>1</tpImp>
<tpEmis>1</tpEmis>
<cDV>6</cDV>
<tpAmb>2</tpAmb>
<finNFe>1</finNFe>
<indFinal>1</indFinal>
<indPres>3</indPres>
<procEmi>3</procEmi>
<verProc>3.10.43</verProc>
</ide>
<emit>
<CNPJ>00822602000124</CNPJ>
<xNome>Plotag Sistemas e Suprimentos Ltda</xNome>
<xFant>Plotag - Localhost</xFant>
<enderEmit>
<xLgr>Rua Solon</xLgr>
<nro>558</nro>
<xBairro>Bom Retiro</xBairro>
<cMun>3550308</cMun>
<xMun>Sao Paulo</xMun>
<UF>SP</UF>
<CEP>01127010</CEP>
<cPais>1058</cPais>
<xPais>BRASIL</xPais>
<fone>1123587604</fone>
</enderEmit>
<IE>114489114119</IE>
<CRT>1</CRT>
</emit>
<dest>
<CNPJ>99999999000191</CNPJ>
<xNome>NF-E EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL</xNome>
<enderDest>
<xLgr>Rua Jaragua</xLgr>
<nro>774</nro>
<xBairro>Bom Retiro</xBairro>
<cMun>3550308</cMun>
<xMun>Sao Paulo</xMun>
<UF>SP</UF>
<CEP>01129000</CEP>
<cPais>1058</cPais>
<xPais>BRASIL</xPais>
<fone>33933501</fone>
</enderDest>
<indIEDest>9</indIEDest>
<email>gui_calabria@yahoo.com.br</email>
</dest>
<det nItem="1">
<prod>
<cProd>B17025056</cProd>
<cEAN/>
<xProd>PAPEL MAXPLOT- 170MX250MX56GRS 3"</xProd>
<NCM>48025599</NCM>
<CFOP>5101</CFOP>
<uCom>Rl</uCom>
<qCom>1.0000</qCom>
<vUnCom>138.3000</vUnCom>
<vProd>138.30</vProd>
<cEANTrib/>
<uTrib>RL</uTrib>
<qTrib>1.0000</qTrib>
<vUnTrib>138.3000</vUnTrib>
<indTot>1</indTot>
</prod>
<imposto>
<vTotTrib>41.49</vTotTrib>
<ICMS>
<ICMSSN101>
<orig>0</orig>
<CSOSN>101</CSOSN>
<pCredSN>2.5600</pCredSN>
<vCredICMSSN>3.54</vCredICMSSN>
</ICMSSN101>
</ICMS>
<IPI>
<clEnq>48025</clEnq>
<CNPJProd>00822602000124</CNPJProd>
<cEnq>599</cEnq>
<IPINT>
<CST>53</CST>
</IPINT>
</IPI>
<PIS>
<PISNT>
<CST>07</CST>
</PISNT>
</PIS>
<COFINS>
<COFINSNT>
<CST>07</CST>
</COFINSNT>
</COFINS>
</imposto>
</det>
<det nItem="2">
<prod>
<cProd>1070100752</cProd>
<cEAN/>
<xProd>PAPEL MAXPLOT- 1070X100MX75GRS 2"</xProd>
<NCM>48025599</NCM>
<CFOP>5101</CFOP>
<uCom>RL</uCom>
<qCom>1.0000</qCom>
<vUnCom>48.9100</vUnCom>
<vProd>48.91</vProd>
<cEANTrib/>
<uTrib>RL</uTrib>
<qTrib>1.0000</qTrib>
<vUnTrib>48.9100</vUnTrib>
<indTot>1</indTot>
</prod>
<imposto>
<vTotTrib>14.67</vTotTrib>
<ICMS>
<ICMSSN101>
<orig>0</orig>
<CSOSN>101</CSOSN>
<pCredSN>2.5600</pCredSN>
<vCredICMSSN>1.25</vCredICMSSN>
</ICMSSN101>
</ICMS>
<IPI>
<clEnq>48025</clEnq>
<CNPJProd>00822602000124</CNPJProd>
<cEnq>599</cEnq>
<IPINT>
<CST>53</CST>
</IPINT>
</IPI>
<PIS>
<PISNT>
<CST>07</CST>
</PISNT>
</PIS>
<COFINS>
<COFINSNT>
<CST>07</CST>
</COFINSNT>
</COFINS>
</imposto>
</det>
<det nItem="3">
<prod>
<cProd>B17025056</cProd>
<cEAN/>
<xProd>PAPEL MAXPLOT- 170MX250MX56GRS 3"</xProd>
<NCM>48025599</NCM>
<CFOP>5101</CFOP>
<uCom>Rl</uCom>
<qCom>1.0000</qCom>
<vUnCom>138.3000</vUnCom>
<vProd>138.30</vProd>
<cEANTrib/>
<uTrib>RL</uTrib>
<qTrib>1.0000</qTrib>
<vUnTrib>138.3000</vUnTrib>
<indTot>1</indTot>
</prod>
<imposto>
<vTotTrib>41.49</vTotTrib>
<ICMS>
<ICMSSN101>
<orig>0</orig>
<CSOSN>101</CSOSN>
<pCredSN>2.5600</pCredSN>
<vCredICMSSN>3.54</vCredICMSSN>
</ICMSSN101>
</ICMS>
<IPI>
<clEnq>48025</clEnq>
<CNPJProd>00822602000124</CNPJProd>
<cEnq>599</cEnq>
<IPINT>
<CST>53</CST>
</IPINT>
</IPI>
<PIS>
<PISNT>
<CST>07</CST>
</PISNT>
</PIS>
<COFINS>
<COFINSNT>
<CST>07</CST>
</COFINSNT>
</COFINS>
</imposto>
</det>
<det nItem="4">
<prod>
<cProd>B17040056</cProd>
<cEAN/>
<xProd>PAPEL MAXPLOT - 1.700X400MX 56 GRS 3"</xProd>
<NCM>48025599</NCM>
<CFOP>5101</CFOP>
<uCom>Rl</uCom>
<qCom>1.0000</qCom>
<vUnCom>214.5700</vUnCom>
<vProd>214.57</vProd>
<cEANTrib/>
<uTrib>Rl</uTrib>
<qTrib>1.0000</qTrib>
<vUnTrib>214.5700</vUnTrib>
<indTot>1</indTot>
</prod>
<imposto>
<vTotTrib>64.37</vTotTrib>
<ICMS>
<ICMSSN101>
<orig>0</orig>
<CSOSN>101</CSOSN>
<pCredSN>2.5600</pCredSN>
<vCredICMSSN>5.49</vCredICMSSN>
</ICMSSN101>
</ICMS>
<IPI>
<clEnq>48025</clEnq>
<CNPJProd>00822602000124</CNPJProd>
<cEnq>599</cEnq>
<IPINT>
<CST>53</CST>
</IPINT>
</IPI>
<PIS>
<PISNT>
<CST>07</CST>
</PISNT>
</PIS>
<COFINS>
<COFINSNT>
<CST>07</CST>
</COFINSNT>
</COFINS>
</imposto>
</det>
<det nItem="5">
<prod>
<cProd>B18525056</cProd>
<cEAN/>
<xProd>PAPEL MAXPLOT-1.85MX250MX56GRS 3"</xProd>
<NCM>48025599</NCM>
<CFOP>5101</CFOP>
<uCom>Rl</uCom>
<qCom>1.0000</qCom>
<vUnCom>149.8300</vUnCom>
<vProd>149.83</vProd>
<cEANTrib/>
<uTrib>RL</uTrib>
<qTrib>1.0000</qTrib>
<vUnTrib>149.8300</vUnTrib>
<indTot>1</indTot>
</prod>
<imposto>
<vTotTrib>44.95</vTotTrib>
<ICMS>
<ICMSSN101>
<orig>0</orig>
<CSOSN>101</CSOSN>
<pCredSN>2.5600</pCredSN>
<vCredICMSSN>3.84</vCredICMSSN>
</ICMSSN101>
</ICMS>
<IPI>
<clEnq>48025</clEnq>
<CNPJProd>00822602000124</CNPJProd>
<cEnq>599</cEnq>
<IPINT>
<CST>53</CST>
</IPINT>
</IPI>
<PIS>
<PISNT>
<CST>07</CST>
</PISNT>
</PIS>
<COFINS>
<COFINSNT>
<CST>07</CST>
</COFINSNT>
</COFINS>
</imposto>
</det>
<total>
<ICMSTot>
<vBC>0.00</vBC>
<vICMS>0.00</vICMS>
<vICMSDeson>0.00</vICMSDeson>
<vBCST>0.00</vBCST>
<vST>0.00</vST>
<vProd>689.91</vProd>
<vFrete>0.00</vFrete>
<vSeg>0.00</vSeg>
<vDesc>0.00</vDesc>
<vII>0.00</vII>
<vIPI>0.00</vIPI>
<vPIS>0.00</vPIS>
<vCOFINS>0.00</vCOFINS>
<vOutro>0.00</vOutro>
<vNF>689.91</vNF>
<vTotTrib>206.97</vTotTrib>
</ICMSTot>
</total>
<transp>
<modFrete>1</modFrete>
<transporta>
<xNome>Cliente Retira</xNome>
<xEnder>Rua ,</xEnder>
<xMun>Sao Paulo</xMun>
<UF>SP</UF>
</transporta>
<vol>
<qVol>1</qVol>
<marca>S/m</marca>
<nVol>S/n</nVol>
<pesoL>0.000</pesoL>
<pesoB>0.000</pesoB>
</vol>
</transp>
<cobr>
<fat>
<nFat>992346</nFat>
<vOrig>689.91</vOrig>
<vLiq>689.91</vLiq>
</fat>
<dup>
<nDup>992346</nDup>
<dVenc>2015-04-24</dVenc>
<vDup>689.91</vDup>
</dup>
</cobr>
<infAdic>
<infCpl>"DOCUMENTO EMITIDO POR EMPRESA OPTANTE PELO SIMPLES NACIONAL;NAO GERA DIREITO A CREDITO FISCAL DE IPI";"PERMITE O APROVEITAMENTO DE CREDITO DE ICMS NO VALOR DE: R$17,66 CORRESPONDENTE A ALIQUOTA DE 2.56%";Vendedor:1 - Guilherme Kavedikado;Valor Aproximado dos Tributos : R$ 206,97. Fonte IBPT (Instituto Brasileiro de Planejamento Tributario)</infCpl>
</infAdic>
</infNFe>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<Reference URI="#NFe35150300822602000124550010009923461099234656">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue>oWFauN7opm3Q6yKVaHiEBqW3DwU=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>KNhzxr9mt2fNcqf4+UIU9XrkzNqw6qg/Mk/uXCXev6YwWf9iF0hLZiRIqKrlUKicCCBzRTxUOiI/
orc/NtXcAHvX/8LVzlvc/OdiuH+XeqDOgl7KCziu6xN71OW016GQZN6VDOqFwyz3Xp2pPZf56nNs
5CBiLxPtNvX8CM0oMarUKOl8FFZCTnEwWbGXhbShoQ+2MYS9NnC06TCUjXwVQp6T4UAyLjSFuGbD
o2XLpzsVU9UQD2qESpSISGwLEVnRaLeeqJI4MRxtwiEBhSvq0R40sI/ejDHkyAx2XT583msAZV32
i1T+SDM2tIL3zoDQGa4lEm8WxCIKJFluXX7rxg==</SignatureValue><KeyInfo><X509Data><X509Certificate>MIIIajCCBlKgAwIBAgIQTLtMm7tkr6qjM8wZTpUo5jANBgkqhkiG9w0BAQsFADB4MQswCQYDVQQG
EwJCUjETMBEGA1UEChMKSUNQLUJyYXNpbDE2MDQGA1UECxMtU2VjcmV0YXJpYSBkYSBSZWNlaXRh
IEZlZGVyYWwgZG8gQnJhc2lsIC0gUkZCMRwwGgYDVQQDExNBQyBDZXJ0aXNpZ24gUkZCIEc0MB4X
DTE0MTAxMzAwMDAwMFoXDTE1MTAxMjIzNTk1OVowggEMMQswCQYDVQQGEwJCUjETMBEGA1UEChQK
SUNQLUJyYXNpbDELMAkGA1UECBMCU1AxEjAQBgNVBAcUCVNBTyBQQVVMTzE2MDQGA1UECxQtU2Vj
cmV0YXJpYSBkYSBSZWNlaXRhI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fk1im9cN8AxLOg61tZ7
jR+aTeFXjQ2Bbw9bEzRHGVq3VZOI6007Z7pwOZ4eqBO0I/LT+BHZ2SnFJ8UKOI1xgL5EMapIZLbJ
+lr3bJcjl0WoPlxZs8TvutjG9Fbv08ZpgPo35IRx9K1aDJ514sDTqHwQgXYI279o7i+JJylH3rDv
7ahVNgJgkfS/j5b0P1ggwQnPtbSDLPt3LX0A+wa9zrTxz5v0/ALddjEFoBkyp+SN6H605yenmy0x
Cj7bxTnL+am8nrxufOQXdpHFRGuBhhe0qlRM+EVyGZbl29kN2zm4OHZCA5KAnMcChDZrY3QoYlLK
k3vVkmzq0AGmoO4CxOr33CBFzLbtDHFAoCotvE+x58E7G3CX3J+t1U5dz8PBBsYNkg==</X509Certificate></X509Data></KeyInfo></Signature></NFe><protNFe versao="3.10"><infProt><tpAmb>2</tpAmb><verAplic>SP_NFE_PL_008f</verAplic><chNFe>35150300822602000124550010009923461099234656</chNFe><dhRecbto>2015-03-27T16:50:50-03:00</dhRecbto><nProt>135150001686732</nProt><digVal>oWFauN7opm3Q6yKVaHiEBqW3DwU=</digVal><cStat>100</cStat><xMotivo>Autorizado o uso da NF-e</xMotivo></infProt></protNFe></nfeProc>]]>
</StringXMLNFe>
<CodSefazRejeicao/>
<MotivoRejeicao/>
</BlocoNFe>
<NroPedidoRegistrado>001</NroPedidoRegistrado>
</ResponseBlocoGraos>
</ns0:MT_GraosSAP_Resp>''')
/*
First creating the variable to receive the <!CADATA[[]> the NF-e XML that it's inside the tag
<StringXMLNFe>, performing a substring indexOF of each values that must be extracted from this NF-e
string as:
<cStat>
<chNFe>
<verAplic>
<tpAmb>
<cUF>
<digVal>
<dhRecbto>
<xMotivo>
<cNF>
<serie>
<nProt>
Storing the values in the correspondent Strings that later one will be used with the replace function to
add in the current structure that later one will be replaced by a new XML that will be build using
StreamingMarkupBuilder .
Code below:
*/
def cdataAsStr = xmlInput.depthFirst().find { it.name() == 'StringXMLNFe' }.toString()
String cStat = cdataAsStr.substring(cdataAsStr.indexOf("<cStat>") + 7,cdataAsStr.indexOf("</cStat>"))//AutorizadoPorSefaz
String chNFe = cdataAsStr.substring(cdataAsStr.indexOf("<chNFe>") + 7,cdataAsStr.indexOf("</chNFe>"))//ClaveDeAcesso
String verAplic = cdataAsStr.substring(cdataAsStr.indexOf("<verAplic>")+10, cdataAsStr.indexOf("</verAplic>"));//Codigo
String tpAmb = cdataAsStr.substring(cdataAsStr.indexOf("<tpAmb>") + 7,cdataAsStr.indexOf("</tpAmb>")) //CodigoAmbiente
String cUF = cdataAsStr.substring(cdataAsStr.indexOf("<cUF>")+5, cdataAsStr.indexOf("</cUF>")); //CodigoEstado
String digestVal = cdataAsStr.substring(cdataAsStr.indexOf("<digVal>") + 8,cdataAsStr.indexOf("</digVal>"))//DigestValue
String dhRecbto = cdataAsStr.substring(cdataAsStr.indexOf("<dhRecbto>")+11,cdataAsStr.indexOf("</dhRecbto>"))//FechaRecibo
String xMotivo = cdataAsStr.substring(cdataAsStr.indexOf("<xMotivo>") + 10,cdataAsStr.indexOf("</xMotivo>"))//Motivo
String nroNotaFiscal = cdataAsStr.substring(cdataAsStr.indexOf("<cNF>") + 5,cdataAsStr.indexOf("</cNF>"))//NroNotaFiscal
String nroSerieNotaFiscal =cdataAsStr.substring(cdataAsStr.indexOf("<serie>") + 7,cdataAsStr.indexOf("</serie>"))//NroSerieNotaFiscal
String nProt = cdataAsStr.substring(cdataAsStr.indexOf("<nProt>") + 8,cdataAsStr.indexOf("</nProt>"))//NumeroProtocolo
/*
ReplaceNode Function from XmlSlurper() class in Groovy Parsing XML mechanism.
You must select the correct position that you would like replace inside the current XML response
in this case I would like to add the new Structure "NotaFiscalResponse" under the value "<Ok>"
Current Value without <NotaFiscalResponse>:
<ReceiveMovimientoAsientosNotaFiscal>
<Response>
<AsientoResponse>
<Code>01</Code>
<Description>Test Material Description</Description>
</AsientoResponse>
<MovimientoResponse>
<Code>007</Code>
<Description>Test Finance Description</Description>
</MovimientoResponse>
<NotaFiscalResponse>
<MensajeError>1</MensajeError>
<NroComprobanteSAP>1</NroComprobanteSAP>
<NroComprobanteSPET>1</NroComprobanteSPET>
<Ok>OK</Ok>
<StringXMLNFe>
Code below:
*/
xmlInput.ResponseBlocoGraos.BlocoNFe.OK.replaceNode {
node -> mkp.yield(node)
RespuestaSefaz{
AutorizadoPorSefaz(cStat)
ClaveAcesso (chNFe);
Codigo(verAplic)
CodigoAmbiente(tpAmb)
CodigoEstado(cUF)
DigestValue(digestVal)
DigitoVerificador(chNFe.substring(43,44))
FechaRecido(dhRecbto)
Motivo(xMotivo)
NroNotaFiscal(nroNotaFiscal)
NroSerieNotaFiscal(nroSerieNotaFiscal)
NumeroProtocolo(nProt)
}
XMLNFe(cdataAsStr)
NroPedidoRegistrado("2020")
}
/*
ReplaceNode Function from XmlSlurper() class in Groovy Parsing XML mechanism to delete the nodes
<StringXMLNFe>,<CodSefazRejeicao> and <MotivoRejeicao> that must be not parsed as a result XML.
*/
xmlInput.ResponseBlocoGraos.BlocoNFe.StringXMLNFe.replaceNode {}
xmlInput.ResponseBlocoGraos.BlocoNFe.CodSefazRejeicao.replaceNode {}
xmlInput.ResponseBlocoGraos.BlocoNFe.MotivoRejeicao.replaceNode {}
/*
StreamingMarkupBuilder generating a new XML copying the result of previous mapping for the structures
AsientoResponse and MovimentoResponse SAP CPI: Graphical Mapping or XSLT/ Mulesoft: Dataweaver or XSLT
*/
def xmlOutput = new StreamingMarkupBuilder().bind {
//Root of XML file
ReceiveMovimientoAsientosNotaFiscal{
//Response structure
Response {
//AsientoResponse Structure
AsientoResponse{
mkp.yield xmlInput.ResponseBlocoGraos.BlocoFI.children()
}
//MovimentoResponse Structure
MovimentoResponse {
mkp.yield xmlInput.ResponseBlocoGraos.BlocoMM.children()
}
}
//Creating based on the structure created above using mpk.yield <RespustasSefaz> and using replaceNode function used above
NotaFiscalResponse{
mkp.yield xmlInput.ResponseBlocoGraos.BlocoNFe.children()
}
}
}
/*
Using the class XmlUtil function serialize to pretty print the XML file
*/
println groovy.xml.XmlUtil.serialize(xmlOutput);
}
}
About Online Groovy Compiler
Try our Online Groovy Compiler (Version Groovy v2.4.21) to Edit, Run, and Share your Groovy Code directly from your browser. This online development environment provides you the latest version Groovy v2.4.21.
How to use Online Groovy Compiler?
Write and Execute Code
- Write your program (or, paste it) directly under the "Source Code" tab.
- If you want to save your program, go to the "Project" menu and save it.
- You can directly execute your program without saving it by clicking on on "Execute" button.
User Input
The latest version of Coding Ground allows to provide program input at run time from the termnial window exactly the same way as you run your program at your own computer. So simply run a program and provide your program input (if any) from the terminal window available in the right side.
Online Groovy Compiler: Keyboard Shortcuts
The following are the keyword shortcut of this Online Groovy Compiler:
Shortcut | Description |
⌘ + Enter | Run the program |
⌘ + S | Save Project (Login Required) |
⇧ + ⌘ + S | Save As Project |
⌘ + P | New Project |
⌘ + G | Share Project |
⌘ + Z | Undo Editing |
⌘ + Y | Redo Editing |
⌘ + A | Select All Text |
⌘ + X | Cut Selected Text |
⌘ + C | Copy Selected Text |
⌘ + V | Paste Copied Text |
⌘ + F | Search Text |
⌘ + ⌥ + F | Replace Text |
Shortcut | Description |
Ctrl + Enter | Run the program |
Ctrl + S | Save Project |
Shift + Ctrl + S | Save As Project |
Ctrl + G | Share Project |
Ctrl + Z | Undo Editing |
Ctrl + Y | Redo Editing |
Ctrl + A | Select All Text |
Ctrl + X | Cut Selected Text |
Ctrl + C | Copy Selected Text |
Ctrl + V | Paste Copied Text |
Ctrl + F | Search Text |
Ctrl + H | Replace Text |
Online Groovy Compiler: Save and Share Groovy Code (Project)
Save Groovy Project Online
You can save your Groovy Project with us so that you can access this project later on. To save a project you will need to create a login Id with us. So before you save a project, please create a login Id using a link given at the top right corner of this page.
Share Groovy Project Online
You can use this feature to share your Groovy Code with your teachers, classmates and colleagues. Just click Share Button and it will create a short link, which can be shared through Email, WhatsApp or even through Social Media. A shared link will be deleted if it has been passive for almost 3 months.
More Features of Online Groovy Compiler
- Theme – You can change the current editor's theme from the "Editor Theme" option under "Settings" menu.
- Font Size – You can change the font size of the editor /compiler from from the "Font Size" option under "Settings" menu.
- Tab Size – You can change the tab size from the "Tab Size" option under "Settings" Menu.
- Show/Hide Line Numbers – You can show/hide the line number with the code from the "Show Line Numbers" or "Hide Line Numbers" option under "Settings" Menu.
- And, many more.
Benefits of Using Online Groovy Compiler
There are several benefits of using the Online Groovy Compiler to run your Groovy code:
- Platform independence: You can run your code from any device without taking care of operating systems.
- Convenience: You don't need to install anything for using this.
- No setup required: There is no need for additional setup to run your code.
- Updated version: Our online compiler/editors/terminals are the latest up-to-date.