Is transforming contents of XML file supported.? #233

Closed
opened 2025-12-29 08:24:30 +01:00 by adam · 6 comments
Owner

Originally created by @dileepsam on GitHub (Dec 4, 2019).

Originally assigned to: @StefH on GitHub.

Hi,

I am trying to use this as a standalone app to mock the server,
when configured an XML file as a response,

how to transform the contents of the file.?

Thanks,

Originally created by @dileepsam on GitHub (Dec 4, 2019). Originally assigned to: @StefH on GitHub. Hi, I am trying to use this as a standalone app to mock the server, when configured an XML file as a response, how to transform the contents of the file.? Thanks,
adam added the bug label 2025-12-29 08:24:30 +01:00
adam closed this issue 2025-12-29 08:24:30 +01:00
Author
Owner

@StefH commented on GitHub (Dec 4, 2019):

An XML response is just plain text, so you can transform all things you like.

@StefH commented on GitHub (Dec 4, 2019): An XML response is just plain text, so you can transform all things you like.
Author
Owner

@dileepsam commented on GitHub (Dec 4, 2019):

I have configured response like below

"Response": {
    "BodyAsFile": "Success.xml",
    "Headers": {
      "Content-Type": "application/xml; charset=UTF-8"
    },
    "StatusCode": 201,
    "UseTransformer": true
  }

Success.xml contains Handlebar transformation which does not seem to work.

Am I missing something.?

@dileepsam commented on GitHub (Dec 4, 2019): I have configured response like below ``` "Response": { "BodyAsFile": "Success.xml", "Headers": { "Content-Type": "application/xml; charset=UTF-8" }, "StatusCode": 201, "UseTransformer": true } ``` Success.xml contains Handlebar transformation which does not seem to work. Am I missing something.?
Author
Owner

@StefH commented on GitHub (Dec 5, 2019):

Currently the transformation is only done for the filename, not yet for the file contents.

I'll take a look.

@StefH commented on GitHub (Dec 5, 2019): Currently the transformation is only done for the filename, not yet for the file contents. I'll take a look.
Author
Owner

@StefH commented on GitHub (Dec 5, 2019):

A preview NuGet is available on MyGet: WireMock.Net.1.0.38-ci-12271.nupkg

You need to provide an extra property ("UseTransformerForBodyAsFile": true)in the mapping:

{
    "Guid": "fd8ca21b-db82-48bc-ae5a-fc2153c2b0db",
    "Request": {
        "Path": {
            "Matchers": [
                {
                    "Name": "WildcardMatcher",
                    "Pattern": "/bodyasfile_transform123"
                }
            ]
        },
        "Methods": [
            "get"
        ]
    },
    "Response": {
        "StatusCode": 200,
        "Headers": { "Content-Type": "application/xml" },
        "BodyAsFile": "c:\\temp-wiremock\\__admin\\mappings\\_{{request.query.MyUniqueNumber}}_\\MyXmlResponse.xml",
    	"UseTransformer": true,
    	"UseTransformerForBodyAsFile": true
    }
}
@StefH commented on GitHub (Dec 5, 2019): A preview NuGet is available on MyGet: `WireMock.Net.1.0.38-ci-12271.nupkg` You need to provide an extra property (`"UseTransformerForBodyAsFile": true`)in the mapping: ``` js { "Guid": "fd8ca21b-db82-48bc-ae5a-fc2153c2b0db", "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/bodyasfile_transform123" } ] }, "Methods": [ "get" ] }, "Response": { "StatusCode": 200, "Headers": { "Content-Type": "application/xml" }, "BodyAsFile": "c:\\temp-wiremock\\__admin\\mappings\\_{{request.query.MyUniqueNumber}}_\\MyXmlResponse.xml", "UseTransformer": true, "UseTransformerForBodyAsFile": true } } ```
Author
Owner

@dileepsam commented on GitHub (Dec 6, 2019):

Thank you, Stef.
It works.

@dileepsam commented on GitHub (Dec 6, 2019): Thank you, Stef. It works.
Author
Owner

@StefH commented on GitHub (Dec 6, 2019):

https://github.com/WireMock-Net/WireMock.Net/pull/388

@StefH commented on GitHub (Dec 6, 2019): https://github.com/WireMock-Net/WireMock.Net/pull/388
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#233