Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6247771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:56:08+00:00 2026-05-24T12:56:08+00:00

How to make Builder to not encode ‘śćż’ and other such characters. What I

  • 0

How to make Builder to not encode ‘śćż’ and other such characters.
What I want is ‘całość’ to be literally printed in XML document.
Example:

xml.instruct! :xml, :version => '1.0', :encoding => 'utf-8'
xml.Trader( :'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
            :'xmlns:xsd' => "http://www.w3.org/2001/XMLSchema") do
  xml.Informacje do
    xml.RodzajPaczki 'całość'
    xml.Program 'mine'
    xml.WersjaProgramu '1.0'
  end
end

Output:

<?xml version="1.0" encoding="utf-8"?> 
<Trader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
 <Informacje>  
  <RodzajPaczki>ca&#322;o&#347;&#263;</RodzajPaczki> 
    <Program>mine</Program> 
    <WersjaProgramu>1.0</WersjaProgramu> 
  </Informacje>
</Trader> 

ca&#322;o&#347;&#263; should be całość.
I saw pseudo solution like xml.RodzajPaczki {|t| t << 'całość' } but it does not work correctly. It outdent ‘całość’ to left side of a document.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:56:09+00:00Added an answer on May 24, 2026 at 12:56 pm

    Here is what is happening. As we know by default Builder will escape non ASCII characters like the ones in całość. You’ve also mentioned one possible way to kinda fix it and that is:

    xml.RodzajPaczki {|t| t << 'całość' }
    

    Unfortunately when you pass a block to the RodzajPaczki element, Builder assumes that there will be some inner xml, so it adds a new line and applies the indent. Of course in our case there is only inner text and no xml so we get some unsightly output like:

    <RodzajPaczki>
    całość      </RodzajPaczki>
    

    There is an easy way and a harder way to fix this. First the easy way.

    Configure Indent To Be Zero

    Then you can use the fix from above xml.RodzajPaczki {|t| t << 'całość' } everything will work as expected, but the output will not be pretty printed, it will infact be all on one line:

    <?xml version="1.0" encoding="UTF-8"?><Trader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Informacje><RodzajPaczki>całość</RodzajPaczki><Program>mine</Program><WersjaProgramu>1.0</WersjaProgramu></Informacje></Trader>
    

    You can run this through an external pretty printer if you want it nicely formatted.

    If you simply must have pretty printed output and want no escaping, we need to patch Builder slightly. This is the harder way to fix this issue.

    Patching Builder

    We need to patch the initializer of our XmlMarkup object to add an extra option :escape. At the same time we patch the XmlBase object to take this new option as a parameter. We default this new option to true, to maintain the default behaviour. We then patch the text! method on XmlBase to use our new option to decide if we should escape text of not. Here is what it looks like:

    module Builder
      class XmlBase
        def initialize(indent=0, initial=0, encoding='utf-8', escape=true)
          @indent = indent
          @level  = initial
          @encoding = encoding.downcase
          @escape = escape
        end
    
        def text!(text)
          if @escape
            _text(_escape(text))
          else
            _text(text)
          end
        end
      end
    
      class XmlMarkup
        def initialize(options={})
          indent = options[:indent] || 0
          margin = options[:margin] || 0
          encoding = options[:encoding] || 'utf-8'
          escape = options[:escape]
          if escape == nil
            escape = true
          end
          super(indent, margin, encoding, escape)
          @target = options[:target] || ""
        end
      end
    end
    

    We can now use our newly patched builder in the following way (notice that when we construct the XmlMarkup object we pass in our new :escape options with a value of false):

    xml = Builder::XmlMarkup.new(:target=>STDOUT, :indent=>3, :encoding => 'utf-8', :escape => false)
    xml.instruct! :xml, :version => '1.0', :encoding => 'UTF-8'
    xml.Trader(:'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", :'xmlns:xsd' => "http://www.w3.org/2001/XMLSchema") do 
      xml.Informacje do
        xml.RodzajPaczki('całość')
        xml.Program('mine')
        xml.WersjaProgramu('1.0')
      end
    end
    

    The output is as follows:

    <?xml version="1.0" encoding="UTF-8"?>
    <Trader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <Informacje>
          <RodzajPaczki>całość</RodzajPaczki>
          <Program>mine</Program>
          <WersjaProgramu>1.0</WersjaProgramu>
       </Informacje>
    </Trader>
    

    As desired the text is not escaped. Note that the patch will apply this non-escaping behaviour to all text, so if you only want some of the text to be non-escaped while other text is still escaped you’ll need to patch Builder to a much greater extent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an NSWindow that I defined in interface builder. I want to make
I am not using a tab bar or any other control -- I want
Well I have a simple problem with Nokogiri. I want to make Nokogiri::HTML::Builder to
I'm not an expert and don't want to make a mistake, so please forgive
Why does C++ Builder 6 always compile all files? I make some changes on
I'm wondering how to make a button or input field in Interface Builder react
Make a new AS3 Document in Flash, paste in the following code and run
make is not only useful for building your programming project, but it seems to
To make it short: hibernate doesn't support projections and query by example? I found
Ultimate Goal Is to make something like Magento offers - basically a logic builder,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.