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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:54:03+00:00 2026-05-15T03:54:03+00:00

I am trying the following, but the output XML is badly formed: xml =

  • 0

I am trying the following, but the output XML is badly formed:

 xml = Builder::XmlMarkup.new({:target => display })

xml.instruct!

xml.mail {  
  xml.documents {
    xml.document {
      xml.template {
        xml.source "gallery"
        xml.name "Postcard: Image fill front"
      }
      xml.sections {
        xml.section {
          xml.name "Text"
          xml.text "Hello, world"
        }

        xml.section {
           xml.name "Image"
           xml.attachment "1136946686-3425"
        }
      } #sections
    } #document         
  } #documents

  xml.addresses {
    xml.addressee {
      xml.name "Me"
      xml.address "Street"
      xml.city "San Francisco"
      xml.state "CA"
    }
  }  
}    
@xml_display = xml

I need it to look more like this:

<?xml version="1.0" encoding="UTF-8"?>
<mail>
  <documents>
    <document>
      <template>
        <source>gallery</source>
        <name>Postcard: Image fill front</name>
      </template>
      <sections>
         <section>
           <name>Text</name>
           <text>Hello, World!</text>
          </section>
       <section>
          <name>Image</name>
          <attachment>...attachment id...</attachment>
          </section>
       </sections>
    </document>
  </documents>
  <addressees>
    <addressee>
      <name>John Doe</name>
      <address>123 Main St</address>
      <city>Anytown</city>
      <state>AZ</state>
      <postal-code>10000</postal-code>
    </addressee>
  </addressees>
</mail>

My code ends up looking like this in the view (page source):

<?xml version="1.0" encoding="UTF-8"?><mail/><documents/><document/><template/><source>gallery</source><name>Postcard:  Image fill front</name>

NOTE: The final XML needs to be POSTED to a URL, and I am using rest-client and so want everything to become an instance variable that is passed as the body.

The instance variable is just @xml_display = xml but it’s not working… 🙁

  • 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-15T03:54:04+00:00Added an answer on May 15, 2026 at 3:54 am

    You can pass a block to each of those to nest the items.

    xml.mail do |mail|
      mail.documents do |documents|
        documents.document do |document|
          document.template do |template|
            template.source "gallery"
            template.name "Postcard:  Image fill front"
          end
        end
      end
    end
    

    There’s more information on the builder rubyforge page.

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

Sidebar

Related Questions

I'm trying to validate the following XML but I'm unable to, can you please
I am trying to read the following xml stream but am really struggling. <channelSnapshot
I have been trying to output XML with PHP but encountered a strange(!) error
I'm trying to deserialize the following XML output: <?xml version=1.0 encoding=ISO-8859-1?> <Foo> <Val>Data1</Val> </Foo>
I'm trying to validate an XML file, but I get the following error: Can
Ok so I have the following code. I'm trying to output some xml so
I am trying to list the grails plugins but i get the following output:
Trying to convert the following but am having difficulty. Can anyone see where I'm
I am trying to used following code but I am not getting good performance
I am trying to do the following but I think I must be missing

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.