Salim,

Why the second "<role name" = par?
But there's const StateP (P not PAR).
Wouldn't it be StatePAR ?

If PAR, something like this would solve half of the problem.

It's still ugly code... but, we can improve it together.

require 'rexml/document'
include REXML
file = File.new("xmlfile.xml")
doc = Document.new(file)

doc.elements.each("protocol/role") do |r|
  role = r.attributes["name"].upcase
  states = r.get_elements("states/state")

  # First line
  stm = "typedef int[0,%d] State%s;\n" % [states.size-1, role]

  states.each_with_index do |s, ix|
    # One line for each state
    state = "const State%s %s = %d;\n" % [ role, s.text.upcase, ix]
    stm << state
  end
  puts stm
  puts
end

But, if it's really "P" then we could get the "P" "regexping" the
states for the part before the underline signal.

What language is this?


On Wed, Dec 15, 2010 at 4:28 PM, Salim Reza <saleem.vighio / gmail.com> wrote:
> Salim Reza wrote in post #968699:
>> Daniel Zd wrote in post #968678:
>>> Have you looked into nokogiri?
>>>
>>> Sent from my iPhone
>>
>> No, I could not find it. When did you sent it?
>
> Ok. I tried to look into nokogiri but I could not solve my problem yet.
> Perhaps, i still need help.
>
> --
> Posted via http://www.ruby-forum.com/.
>
>