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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:57:02+00:00 2026-06-17T01:57:02+00:00

I have several XML files that I need to generate Ruby code for. The

  • 0

I have several XML files that I need to generate Ruby code for. The XML structure I have is as follows:

<acronym_list> 
   xmlns="http://www.example.com/xsds" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
   xsi:schemaLocation="http://www.example.com/xsds           
                       http://www.example.com/xsds/acronyms.xsd">
 <item>
   <metadata>
     <release>...</release>
     <id>...</id>
     <checkdigit>...<checkdigit>
     <status>...</status>
     <date_added>...</date_added>
     <date_modified>...</date_modified>
     <language>...</language>
     <license_url>...</license_url>
   </metadata>
   <info>
     <name>...</name>
   </info>
 </item>
</acronym_list>

In this case, we’re talking about acronyms. The item elements (and their children) are repeated for each acronym I have in my list. I also have several files with a similar structure with the info element having more children.

The Ruby code I’m trying to get out would look like:

Module acronym_list
    def self.included(other)
        include SAXMachine
        SAXMachine.configure(other) do |c|
          c.element :metadata, :class => metadata
          c.element :info, :class => info
        end
    end

    class metadata
       include SAXMachine
       c.element :release
       c.element :id
       c.element :checkdigit
       c.element :status
       c.element :date_added
       c.element :date_modified
       c.element :language
       c.element :license_url
    end

    class info
       include SAXMachine
       c.element :name
    end           
end

The same pattern follows for the other XML files that I’m trying to parse. I’ve managed to get the first part working with the module declaration, but I don’t know enough XSLT to get the rest.

Would somebody be able to help me out with this?

  • 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-17T01:57:04+00:00Added an answer on June 17, 2026 at 1:57 am

    I don’t know the ruby syntax so I am not sure whether indentation or whitespace matters but with the stylesheet

    <xsl:stylesheet version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:acs="http://www.example.com/xsds"
      exclude-result-prefixes="acs">
    
    <xsl:output method="text"/>
    <xsl:strip-space elements="*"/>
    
    <xsl:template match="acs:acronym_list">
    Module <xsl:value-of select="local-name()"/>
      def self.included(other)
         include SAXMachine
         SAXMachine.configure(other) do |c|
           <xsl:apply-templates select="acs:item/acs:*" mode="config"/>
         end
      end
    
      <xsl:apply-templates select="acs:item/acs:*" mode="class"/>
    end
    </xsl:template>
    
    <xsl:template match="acs:item/acs:*" mode="config">
            c.element :<xsl:value-of select="local-name()"/>, :class => <xsl:value-of select="local-name()"/>
    </xsl:template>  
    
    <xsl:template match="acs:item/acs:*" mode="class">
      class <xsl:value-of select="local-name()"/>
        include SAXMachine
        <xsl:apply-templates mode="class"/>
      end
    </xsl:template>
    
    <xsl:template match="acs:item/acs:*/acs:*" mode="class">
        c.element :<xsl:value-of select="local-name()"/>
    </xsl:template>
    
    </xsl:stylesheet>
    

    Saxon 6.5.5 tansforms the input

    <acronym_list
       xmlns="http://www.example.com/xsds" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
       xsi:schemaLocation="http://www.example.com/xsds           
                           http://www.example.com/xsds/acronyms.xsd">
     <item>
       <metadata>
         <release>...</release>
         <id>...</id>
         <checkdigit>...</checkdigit>
         <status>...</status>
         <date_added>...</date_added>
         <date_modified>...</date_modified>
         <language>...</language>
         <license_url>...</license_url>
       </metadata>
       <info>
         <name>...</name>
       </info>
     </item>
    </acronym_list>
    

    into the output

    Module acronym_list
      def self.included(other)
         include SAXMachine
         SAXMachine.configure(other) do |c|
    
            c.element :metadata, :class => metadata
            c.element :info, :class => info
         end
      end
    
    
      class metadata
        include SAXMachine
    
        c.element :release
        c.element :id
        c.element :checkdigit
        c.element :status
        c.element :date_added
        c.element :date_modified
        c.element :language
        c.element :license_url
      end
    
      class info
        include SAXMachine
    
        c.element :name
      end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several files (they are XML but that's not important) that need to
I have several xml files that are formated this way: <ROOT> <OBJECT> <identity> <id>123</id>
I have several xml files with different node structure. I want to extract xml
I have parametrized junit test that reads from several XML input files. In the
I have several files comprising a tomcat web application that I need to import
I have several medium sized (1 MB) xml file that I frequently need to
I have several existing XML schema files with a defined data model. I would
I have an XML document, several actually, that will be editable via a front-end
I have (quite a bit of) static files that I need to deploy with
I have the following xml file that I need to read into my C#

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.