# XML parsing, block name with minus

**URL:** <https://www.ruby-forum.com/t/xml-parsing-block-name-with-minus/191820>\
**Category:** Rails\
**Created:** [July 19, 2010, 11:38am UTC](https://www.ruby-forum.com/t/xml-parsing-block-name-with-minus/191820 "2010-07-19T11:38:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Szymon\_PrzybySSSS\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@Szymon\_PrzybySSSS\_S](https://www.ruby-forum.com/u/Szymon_PrzybySSSS_S)\
**Post date:** [July 19, 2010, 11:38am UTC](https://www.ruby-forum.com/t/xml-parsing-block-name-with-minus/191820/1 "2010-07-19T11:38:47Z")

</div>

Hi!

I’m trying to parse a XML document (MusicXML), I found that here  
something about it:  
[http://railstips.org/blog/archives/2008/08/11/parsing-xml-with-ruby/](http://railstips.org/blog/archives/2008/08/11/parsing-xml-with-ruby/)

- 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 . 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?

cheers,  
simon

---

<div class="post-metadata">

**Author:** ![Szymon\_PrzybySSSS\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@Szymon\_PrzybySSSS\_S](https://www.ruby-forum.com/u/Szymon_PrzybySSSS_S)\
**Post date:** [July 19, 2010, 11:52am UTC](https://www.ruby-forum.com/t/xml-parsing-block-name-with-minus/191820/2 "2010-07-19T11:52:15Z")

</div>

On 19 Jul 2010, at 11:37, Szymon PrzybyÅ‚ wrote:

> is prohibited. How can I make a symbol name with minus sign?  
> Just use a string instead:

(doc/‘score-partwise’)

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![Szymon\_PrzybySSSS\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@Szymon\_PrzybySSSS\_S](https://www.ruby-forum.com/u/Szymon_PrzybySSSS_S)\
**Post date:** [July 19, 2010, 8:05pm UTC](https://www.ruby-forum.com/t/xml-parsing-block-name-with-minus/191820/3 "2010-07-19T20:05:46Z")

</div>

Szymon PrzybyÅ‚ wrote:  
[…]

> 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:

:‘name-with-weird-characters’  
:“name-with-weird-characters-and-#{variable\_interpolation}”

…or just use String#to\_sym .

We are now well out of Rails territory and into basic Ruby, so further  
discussion probably should go to the main Ruby list.

> cheers,  
> simon

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
