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 8876105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:07:55+00:00 2026-06-14T19:07:55+00:00

I have a small problem when trying build an XML document with Nokogiri. I

  • 0

I have a small problem when trying build an XML document with Nokogiri.

I want to call one of my elements “text” (see the the very bottom of the pasted code below). Normally, to create a new element I do something like the following xml.text — but it seems to be .text is a method already used by Nokogiri to do something else. Thus when I write this line xml.text Nokogiri is not creating a new element called <text> but is just writing the text meant to be the content of the element. How can I get Nokogiri to actually make an element called <text>?

builder = Nokogiri::XML::Builder.new do |xml|   
  xml.TEI("xmlns" => "http://www.tei-c.org/ns/1.0"){
    xml.teiHeader {
        xml.fileDesc{
            xml.titleStmt{
                xml.title "Version Log for #{title}"
                xml.author "Jeffrey C. Witt"
            }
            xml.editionStmt{
                xml.edition('n' => "#{ed_no}") {
                    xml.date('when' => "#{newDate}")
                    }
                }
            xml.publicationStmt{
                xml.publisher "#{publisher}"
                xml.pubPlace "#{pubPlace}"
                xml.availability("status" => "free") {
                    xml.p "Published under a Creative Commons Attribution ShareAlike 3.0 License"
                }
                xml.date("when" => "#{newDate}") 
            }   
            xml.sourceDesc {
                xml.p "born digital"
            }
        }
    }
    xml.text "test"{
      xml.body {
       xml.p "test 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-06-14T19:07:57+00:00Added an answer on June 14, 2026 at 7:07 pm

    From the docs:

    The builder works by taking advantage of method_missing. Unfortunately some methods are defined in ruby that are difficult or dangerous to remove. You may want to create tags with the name “type”, “class”, and “id” for example. In that case, you can use an underscore to disambiguate your tag name from the method call.

    So, all you have to do is add an underscore after text, like so:

    builder = Nokogiri::XML::Builder.new { |xml| xml.text_ "test" }
    builder.to_xml
    #=> "<?xml version=\"1.0\"?>\n<text>test</text>\n"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with a small app I'm trying to build. When I
I have problem with build in VS2010. I´m trying to develop small Prism, MVVM
I have small problem with Spring MVC. Basically what I'm trying to do is
Im having a small problem with my code. I have been trying to read
have small problem, and would very much appreciate help :) I should convert byte
I have a small problem where I want to find the next active item
I'm trying to build small web-system (url shortcutting) using nonsql Cassandra DB, the problem
I've been trying to build this small java app. I find it very difficult
I have a small problem with TFS. I am trying to zip files after
I have to build a small OpenGL wrapper for a work. I'm trying to

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.