J
Jeff Wood
Ok, here's a snippet
def parseElement( currentElement, currentNode )
# Step 1: Load the attributes from currentElement into currentNode
currentElement.attributes.each do |name, value|
currentNode.attributes[name] = value
end
# Step 2: Parse the children.
currentElement.children.each do |currentChild|
if currentChild.kind_of? Text
puts "Ignoring #{currentChild.value}"
end
if currentChild.kind_of? Element
childNode = JWNode.new( currentChild.name )
#################################################################
# PROBLEM HERE ... currentNode doesn't make it into this scope. #
# vvvvvvvvvvvv ##################################################
currentNode.children << childNode
parseElement( currentChild, childNode )
end
end
end
The code is taking an REXML::Element tree ( xml doc ) ... and passing it
in with another object.
As I try to add children to the passed in object, I find that
currentNode at the "PROBLEM HERE" point is Nil
I guess I don't understand Ruby's scoping logic as well as I thought I
did... help?
j.
def parseElement( currentElement, currentNode )
# Step 1: Load the attributes from currentElement into currentNode
currentElement.attributes.each do |name, value|
currentNode.attributes[name] = value
end
# Step 2: Parse the children.
currentElement.children.each do |currentChild|
if currentChild.kind_of? Text
puts "Ignoring #{currentChild.value}"
end
if currentChild.kind_of? Element
childNode = JWNode.new( currentChild.name )
#################################################################
# PROBLEM HERE ... currentNode doesn't make it into this scope. #
# vvvvvvvvvvvv ##################################################
currentNode.children << childNode
parseElement( currentChild, childNode )
end
end
end
The code is taking an REXML::Element tree ( xml doc ) ... and passing it
in with another object.
As I try to add children to the passed in object, I find that
currentNode at the "PROBLEM HERE" point is Nil
I guess I don't understand Ruby's scoping logic as well as I thought I
did... help?
j.