Forum Discussion

darshthakkar's avatar
darshthakkar
Valued Contributor
6 months ago
Solved

Can we generate XML file in pretty print format using native snapLogic snaps?

Hi Team,

 

I was curious to know if anybody has worked on a use case where they are generating an XML file in pretty print format?

We do have "pretty-print" option in JSON formatter however the same is not available in XML formatter snap. Any suggestions?

 

Thanking in advance.

Best Regards,

Darsh

3 Replies

  • darshthakkar's avatar
    darshthakkar
    Valued Contributor

    This was achieved by using a custom python script.

  • darshthakkar's avatar
    darshthakkar
    Valued Contributor

    Just to add here, I've tried with uploading XSD and writing a python script too but the results are not intended.

    Thank you.

     

    Best Regards,

    Darsh

    • XanderVR's avatar
      XanderVR
      New Contributor

      Just to add, as I see you already have a solution.
      I have managed to achieve the same by using the XSLT Snap with an XSLT that only pretty prints the XML.
      In this XSLT snap I also did a validation on an XSD on the incoming data.

      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      	<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
          <!-- Identity template : copy all text nodes, elements and attributes -->
          <xsl:template match="@*|node()">
              <xsl:copy>
                  <xsl:apply-templates select="@*|node()"/>
              </xsl:copy>
          </xsl:template>
      </xsl:stylesheet>