XML API - Replacement of Characters (XML Entities)
Nobody has claimed this yet.
- Dominant language
- PowerShell
- Stars
- 881
- Forks
- 285
- Avg merge
- 3d 36m
- Merged PRs (30d)
- 1
Description
Hi,
I am currently trying to generate some XML using AL's XML API.
While the generation itself works just fine, I am encountering an issue when it comes to format specific requirements.
The receiver of the XML file forces me to replace the chars ', ", <, >, & with their respective XML entities ', ", <, >, &, regardless of their location in the document (Attribute or Textnode value). However XmlElement.SetAttribute() and XmlText.Create() only replace some of those chars in order to keep the document wellformed.
Attributes:
"-->"<--><>-->>&-->&
Textnodes:
<--><>-->>&-->&
Example
AL Code:
el := XmlElement.Create('greeting');
el.Add(XmlText.Create('''"Hello<>&'));
el.SetAttribute('lang', '''"en-US<>&');
Actual output:
<greeting lang="'"en-US<>&">
'"Hello<>&
</greeting>
Required output:
<greeting lang="'"en-US<>&">
'"Hello<>&
</greeting>
So ' (') is never replaced, while " (") is only replaced when used in an attribute. Although this makes perfect sense, I need to replace all of the mentioned chars as per the requirements.
I tried to manually replace the chars with their respective XML entities before adding the text to an attribute / textnode, but, for example, instead of ' i got &apos;, because Ampersands are replaced automatically when adding the preprocessed text. In the past (using C/AL and DotNet) we solved this by using XmlEntityReference, but as there currently is no such class in AL, I can't think of a possible solution for my problem.
Can anyone think of a solution for this? Or, if there currently is no way to accomplish what i am trying to do, would it be possible to add XmlEntityReference to AL's XML API?
Thanks in advance.
Kind Regards,
Josh
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the XML API behavior of XmlElement.SetAttribute() and XmlText.Create(), then compare it with the requested XmlEntityReference support. The issue is complete when the AL XML API can emit the required entities without double-escaping, or clearly documents that this output is unsupported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- xml
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100