none
Transform-XML omit-xml-declaration

    Question

  • I have a flat-file pipe delimited file coming in. I can use decode, transform, etc. All is good.

    1. FTP when file created

    2. Flat File Decoding

    3. Transform XML

    4. Create File

    I can write the file out to FTP - This is great!!

    Issue:  In output xml I need the following result

    Current Output: <?xml version="1.0" encoding="UTF-8"?>

    What I need: <?xml version="1.0"?>

    Nothing I seem to do makes this happen. Here is XLST from Map file:

    <?xml version="1.0" encoding="UTF-16"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0" version="1.0" xmlns:ns0="http://DICOM_LogicApp.DICOM_XMLOutput_UTF8" xmlns:s0="http://DICOM_LogicApp.DICOM_FlatFileUTF8">
      <xsl:import href="https://az818438.vo.msecnd.net/functoids/functoidsscript.xslt" />
      <xsl:output omit-xml-declaration="yes" indent="yes" version="1.0" method="xml" />
      <xsl:template match="/">
        <xsl:apply-templates select="/s0:Root" />
      </xsl:template>
      <xsl:template match="/s0:Root">

    Any help would be greatly appreciated. This seems like such a simple task, but I must be missing something.


    Brian A. Lemaster Tecodo, Inc.

    Wednesday, March 1, 2017 4:24 PM

Answers

  • Hi Brian,

    First things I was going to suggest is exactly what you did in XSLT. An ugly workaround is to use a replace function while you are sending the message to ftp. Something like

    @xml(replace(string(body('yourtransformaction')),'<?xml version=\"1.0\" encoding=\"UTF-16\"?>',''))

    Im assuming you want to send it out as xml - that is why the @xml in the beggining.

    As I've said, ugly, but might do the trick since, as Padma said, seems like the action currently ignores the omit XML declaration in XSLT.

    I hope this helps, Wagner.

    Thursday, March 2, 2017 3:21 AM
  • Wagner,

    I finally figured this out. Could not have done it without your input.  I figured replace or regular expression was the fix, but I do not know how to do that.

    To solve this, I created a 'Compose' action and added the following code:

     "actions": {
                "Compose": {
                    "inputs": "@replace(string(body('Transform_XML')),'<?xml version=\"1.0\" encoding=\"utf-8\"?>','<?xml version=\"1.0\"?>')",
                    "runAfter": {
                        "Transform_XML": [
                            "Succeeded"
                        ]
                    },
                    "type": "Compose"
                },

    This did the trick.  Do you think I should do it somewhere else?  This does work though.

    I have one more question.

    Original FTP file is: fileinput.txt which is pipe delimited, this works.

    When I go to create file in Destination FTP, I need to change the file extension from .TXT to .XML

    Could you help with that, would it be along the same lines?


    Brian A. Lemaster Tecodo, Inc.

    Thursday, March 2, 2017 4:45 PM

All replies

  • Right now it is not possible to omit the encoding.  Can you share your input file, map and schema to check the possibility.

    Thanks

    Padma

    Wednesday, March 1, 2017 10:21 PM
  • you can share details to padmavc@microsoft.com
    Wednesday, March 1, 2017 10:25 PM
  • Hi Brian,

    First things I was going to suggest is exactly what you did in XSLT. An ugly workaround is to use a replace function while you are sending the message to ftp. Something like

    @xml(replace(string(body('yourtransformaction')),'<?xml version=\"1.0\" encoding=\"UTF-16\"?>',''))

    Im assuming you want to send it out as xml - that is why the @xml in the beggining.

    As I've said, ugly, but might do the trick since, as Padma said, seems like the action currently ignores the omit XML declaration in XSLT.

    I hope this helps, Wagner.

    Thursday, March 2, 2017 3:21 AM
  • This has been an issue since before the EIP "took" the transformation functionality: https://github.com/Azure/azure-quickstart-templates/issues/2730

    There is a work around in the code for the Function code.


    //Mikael Sand - Enfo Sweden If you find any post helpful, please mark it as such. If I answer your question, humor me with a thank you or mark as answer.

    Thursday, March 2, 2017 7:13 AM
  • Wagner, thank you for this. I figured this would be the ugly way.

    Now, since I am new to this, where would I put this line?  In the Logic App Code view? Below is my code view:

     "$connections": {
            "value": {
                "ftp_1": {
                    "connectionId": "/subscriptions/",
                    "connectionName": "ftp-1",
                    "id": "/subscriptions/"
                },
                "sftp": {
                    "connectionId": "/subscriptions/",
                    "connectionName": "sftp",
                    "id": "/subscriptions/"
                }
            }
        },
        "definition": {
            "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
            "actions": {
                "Create_file": {
                    "inputs": {
                        "body": "@body('Transform_XML')",
                        "host": {
                            "api": {
                                "runtimeUrl": "https://logic-apis-centralus.azure-apim.net/apim/ftp"
                            },
                            "connection": {
                                "name": "@parameters('$connections')['ftp_1']['connectionId']"
                            }
                        },
                        "method": "post",
                        "path": "/datasets/default/files",
                        "queries": {
                            "folderPath": "/steve",
                            "name": "@{triggerOutputs()['headers']['x-ms-file-name']}"
                        }
                    },
                    "runAfter": {
                        "Transform_XML": [
                            "Succeeded"
                        ]
                    },
                    "type": "ApiConnection"
                },
                "Flat_File_Decoding": {
                    "inputs": {
                        "content": "@{triggerBody()}",
                        "integrationAccount": {
                            "schema": {
                                "name": "Production-DICOM-FFInput"
                            }
                        }
                    },
                    "runAfter": {},
                    "type": "FlatFileDecoding"
                },
                "Transform_XML": {
                    "inputs": {
                        "content": "@{body('Flat_File_Decoding')}",
                        "integrationAccount": {
                            "map": {
                                "name": "6Map"
                            }
                        }
                    },
                    "runAfter": {
                        "Flat_File_Decoding": [
                            "Succeeded"
                        ]
                    },
                    "type": "Xslt"
                }
            },
            "contentVersion": "1.0.0.0",
            "outputs": {},
            "parameters": {
                "$connections": {
                    "defaultValue": {},
                    "type": "Object"
                }
            },
            "triggers": {
                "When_a_file_is_added_or_modified": {
                    "inputs": {
                        "host": {
                            "api": {
                                "runtimeUrl": "https://logic-apis-centralus.azure-apim.net/apim/sftp"
                            },
                            "connection": {
                                "name": "@parameters('$connections')['sftp']['connectionId']"
                            }
                        },
                        "method": "get",
                        "path": "/datasets/default/triggers/onupdatedfile",
                        "queries": {
                            "folderId": "L0RpY29tTWFuaWZlc3RQaWNrdXA=",
                            "includeFileContent": true
                        }
                    },
                    "metadata": {
                        "L0RpY29tTWFuaWZlc3RQaWNrdXA=": "/DicomManifestPickup"
                    },
                    "recurrence": {
                        "frequency": "Minute",
                        "interval": 1
                    },
                    "type": "ApiConnection"
                }
            }
        }
    }


    Brian A. Lemaster Tecodo, Inc.

    Thursday, March 2, 2017 1:44 PM
  • What is the work around? Wagner had good idea that would work, but what is your work around.  I could use some guidance on where to put the work around.

    Brian A. Lemaster Tecodo, Inc.

    Thursday, March 2, 2017 1:46 PM
  • Wagner,

    I finally figured this out. Could not have done it without your input.  I figured replace or regular expression was the fix, but I do not know how to do that.

    To solve this, I created a 'Compose' action and added the following code:

     "actions": {
                "Compose": {
                    "inputs": "@replace(string(body('Transform_XML')),'<?xml version=\"1.0\" encoding=\"utf-8\"?>','<?xml version=\"1.0\"?>')",
                    "runAfter": {
                        "Transform_XML": [
                            "Succeeded"
                        ]
                    },
                    "type": "Compose"
                },

    This did the trick.  Do you think I should do it somewhere else?  This does work though.

    I have one more question.

    Original FTP file is: fileinput.txt which is pipe delimited, this works.

    When I go to create file in Destination FTP, I need to change the file extension from .TXT to .XML

    Could you help with that, would it be along the same lines?


    Brian A. Lemaster Tecodo, Inc.

    Thursday, March 2, 2017 4:45 PM
  • Hi Brian,

    Sorry for the lack of comms - I was locked in a hackathon for two days, so only back in the forums today.

    Your way is the cleanest, as you actually isolate the workaround, so if/when Microsoft change the Transform to allow you to omit the declaration (should be an option in the transform action IMHO), you can remove it.

    Another option (which is uglier) is to put that line in the input of your Create_File action. The only advantage for that is that you have one last action (which might be important if this is a extremely busy logic app, as you will be paying for the extra action, but not so much if it not that busy).

    I personally prefer how you implemented. And really happy I was of some help.

    Cheers, Wagner.

    Sunday, March 5, 2017 10:40 AM