XML Encoding Not Working
See original GitHub issueI am using a symbol to replace content in a csproj
file. I understand from https://github.com/dotnet/templating/issues/368 that I can XML encode the contents like so:
"symbols": {
"Title": {
"type": "parameter",
"datatype": "string",
"defaultValue": "Project Title",
"replaces": "PROJECT-TITLE",
"description": "The name of the project which determines the assembly product name.",
"forms": [ "encode" ]
},
"forms": {
"encode": {
"identifier": "xmlEncode"
}
}
When I run:
dotnet new graphql --name Foo --Title "Foo & Bar"
My csproj file is output with:
<Product>Foo & Bar</Product>
XML encoding is failing to occur. As an aside, what happens if you want to make the replacement in a csproj and separately a json file? i.e. I only want to XML encode when I replace the content in the csproj file and not the JSON file.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to Fix XML Files with Bad Encoding - FME Community
Fixing this problem means re-encoding the XML data with the proper encoding scheme. To do this, create an FME Workspace to convert the...
Read more >XML encoding issue
A proper XML parser will fail to load an XML document if it contains any invalid characters - that is, byte sequences which...
Read more >XML Encoding failing due Encoding not being UTF-8
The main reason for this error is that, the XML Parser cannot parse the XML since it contains non UTF-8 encoded characters. The...
Read more >Error when trying to handle & character in XML message ...
I need to encode special characters like < and > and & and ' and " in a webMethods service. To test it...
Read more >XML encoding and DOM interface methods
This article describes XML encoding and DOM interface methods. ... How to Encode XML Data addresses general XML encoding issues in detail: ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I agree, it is a bit complicated. Here’s another way to do it that you might like better, and doesn’t require sometimes xml encoding in the template source. Not too long ago, we introduced “derived symbols” which allow transforming the value of one symbol into the value of another. So a template could be setup to have a title symbol as a normal string parameter, such as:
And then define a symbol whose value is derived from this symbol, and replaces something else, such as:
The derived symbol’s value is determined by the attributes:
Given the above symbol definitions, and template content of:
…and invoking the template with
--Title "Foo & Bar"
, the content would be transformed to:With this method (if a jsonEncode value form existed), then for adding a json encoded version of the title, and appropriate replacements, we’d just define another derived symbol, such as:
Note that there is no need to have the words “json” or “xml” in the replaces values, I was using those values for clarity.
BTW, I had to add a
datatype
property. The JSON schema needs updating as I was getting warnings abouttype
being set toderived
.