I'm trying to parse a XML document (MusicXML), I found that here
something about it: Parsing XML with Ruby // RailsTips by John Nunemaker
- I chose Hpricot, but I have a problem: in XML document, which I'm
trying to parse, there are names of blocks with minus sign, for
example <score-partwise>. In Hpricot it should looks something like
this:
xml = File.read(path)
puts Benchmark.measure {
doc = Hpricot::XML(xml)
(doc/:score-partwise).each do |s|
# here we have s as each score-partwise block
end
}
But it throws undefined local variable or method `partwise' for
#<MusicxmlController:0xb6badff4>, becouse in symbols names minus sign
is prohibited. How can I make a symbol name with minus sign?
But it throws undefined local variable or method `partwise' for
#<MusicxmlController:0xb6badff4>, becouse in symbols names minus sign
is prohibited. How can I make a symbol name with minus sign?
Well, you can actually have any characters you like in a symbol name.
The :name syntax only works if the symbol name doesn't contain "weird"
characters, but the following syntaxes will work regardless: