LightXML question

I’m reading an XML file that looks like this:

<machine_information>
	<machine name="Raspberry Pi" node="julia-user@NODE-RPI3" julia-bin="/home/julia-user/julia-0.6.0/bin/">
		<pins category="GPIO">
			<!--left pins (left) -->
			<PIN03>2</PIN03>
			<PIN05>3</PIN05>
			<PIN07>4</PIN07>
			<PIN11>17</PIN11>
			<PIN13>27</PIN13>
			<PIN15>22</PIN15>
			<PIN19>10</PIN19>
			<PIN21>9</PIN21>
			<PIN23>11</PIN23>
			<!--left pins (right) -->
			<PIN29>5</PIN29>
			<PIN31>6</PIN31>
			<PIN33>13</PIN33>
			<PIN35>19</PIN35>
			<PIN37>26</PIN37>
			<!--right pins (left) -->
			<PIN08>14</PIN08>
			<PIN10>15</PIN10>
			<PIN12>18</PIN12>
			<PIN16>23</PIN16>
			<PIN18>24</PIN18>
			<PIN22>25</PIN22>
			<PIN24>8</PIN24>
			<PIN26>7</PIN26>
			<!--right pins (right) -->
			<PIN32>12</PIN32>
			<PIN36>16</PIN36>
			<PIN38>20</PIN38>
			<PIN40>21</PIN40>
		</pins>
        </machine>
</machine_information>

I use the following code to get at different aspects:

using LightXML
xdoc = parse_file("RPI3.conf")

# get the root element
xroot = root(xdoc)  # an instance of XMLElement
# print its name
println(name(xroot))  # this should print: machine_information

machine = get_elements_by_tagname(xroot, "machine")
name = attribute(machine[1], "name")
node = attribute(machine[1], "node")
bindir = attribute(machine[1], "julia-bin")
pins = find_element(machine[1], "pins")
pin = collect(child_elements(pins))

So, the last line I am trying to access individual pins in a collection:

julia> pin
26-element Array{Any,1}:
 <PIN03>2</PIN03> 
 <PIN05>3</PIN05> 
 <PIN07>4</PIN07> 
 <PIN11>17</PIN11>
 <PIN13>27</PIN13>
 <PIN15>22</PIN15>
 <PIN19>10</PIN19>
 <PIN21>9</PIN21> 
 <PIN23>11</PIN23>
 <PIN29>5</PIN29> 
 ⋮                
 <PIN16>23</PIN16>
 <PIN18>24</PIN18>
 <PIN22>25</PIN22>
 <PIN24>8</PIN24> 
 <PIN26>7</PIN26> 
 <PIN32>12</PIN32>
 <PIN36>16</PIN36>
 <PIN38>20</PIN38>
 <PIN40>21</PIN40>

If I do content(pin[1]) I get the value “2” - good. content(pin[2]) I get the value “3”. But, I want to get the name of the node, I get an error.

julia> name(pin[2])
ERROR: MethodError: objects of type String are not callable

Am I accessing this correctly? I would like to be able to loop through the pin collection and get the name and the value.

You’ve assigned name a value:

name = attribute(machine[1], "name")

which is masking the name() function that you’re trying to call. Either change the name of your variable to something else or call LightXML.name().

Thanks. That was a duh! moment.