From: Stephen Bannasch Date: 2006-03-24T11:28:54+09:00 Subject: Re: using builder to make jnlp xml elements with "-" in name? [partially answering my own question ...] The reason that builder can't create xml elements with "-" chars in the element is because strings with "-" chars are not legal Ruby symbols. Builder uses method_missing to create the xml element markup and so it seems Ruby's parser chokes when it tries to convert the string into a symbol. I've got a workaround below but it is more general than I want (it replaces all "_" chars with "-"). I left some code commented out that I was trying too get working but didn't. It's a bit confusing to debug because the inheritance chain (XmlMarkup < XmlBase < BlankSlate) end up hiding all the normal methods -- I'm a bit surprised that my code works at all. Anyway, I'm just learning Ruby and figuring out just what is going on here is fun. If anybody has suggestions I'd appreciate it. Thanks #!/usr/bin/env ruby # file: jnlpmarkup.rb # extends Builder::XmlMarkup for creating XML markup for jnlp documents. # Some jnlp elements have a "-" char in the element name. Builder doesn't # accept this character. So this class postprocesses the result and replaces # proxy jnlp element names such as "" with "" # # because I can't get what I intended to work right now this just # replaces all "_" chars with '-' chars require 'builder/xmlmarkup' module Builder class JnlpMarkup < XmlMarkup @@jnlp_in = %w{application_desc applet_desc component_desc installer_desc offline_allowed related_content all_permissions j2ee_application_client_permissions ext_download} @@jnlp_out = %w{application-desc applet-desc component-desc installer-desc offline-allowed related-content all-permissions j2ee-application-client-permissions ext-download} def method_missing(sym, *args, &block) super.gsub(/_/, '-') # various things that didn't work below: # x = super # x = x.gsub(/application_desc/, 'application-desc') # x = x.gsub(/applet_desc/, 'applet_desc') # x = x.gsub(/#{@@jnlp_in[i]}/, @@jnlp_out[i]) # @@jnlp_in.each_index do |i| x = x.gsub(/#{@@jnlp_in[i]}/, @@jnlp_out[i]) end end end end -- - Stephen Bannasch Concord Consortium, http://www.concord.org