Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to not escape ampersand in the attribute of an element? #35

Open
abdulowork opened this issue Jun 8, 2020 · 1 comment
Open

How to not escape ampersand in the attribute of an element? #35

abdulowork opened this issue Jun 8, 2020 · 1 comment

Comments

@abdulowork
Copy link

Hi!

I am trying to create an element with attribute that looks like:

<MyElement
    myAttribute = "Hello&#10;World">
</MyElement>

which I am doing the the following code:

my_attribute = REXML::Text.new('Hello&#10;World')

my_element = REXML::Element.new('MyElement')
my_element.attributes['myAttribute'] = my_attribute

my_element.to_s

and I get Hello&amp;amp;#10;World in the attribute. I also tried using the raw flag for the Text and the { :raw => :all } context for the Element but that removes only a single amp;.

Am I missing something? How can I get to my desired output?

@abdulowork abdulowork changed the title How to not escape ampersand the attribute of an element? How to not escape ampersand in the attribute of an element? Jun 8, 2020
@kou
Copy link
Member

kou commented Jun 8, 2020

If you want to use raw value, you need to use REXML::Attribute instead of REXML::Text:

my_attribute = REXML::Attribute.new('myAttribute', 'Hello&#10;World')

my_element = REXML::Element.new('MyElement')
my_element.attributes['myAttribute'] = my_attribute

my_element.to_s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants