Need help in parsing xml

I have an xml structure like below and would like to store the activity
name attribute as key along with complete inputBindings structure with
xml tags etc as value in a hash -

activityName = Hash.new

Following doesn’t get anything in value -

xml.elements.each("/kp:process/kp:activity"){ |e|
@activityName[e.attributes[“name”]] =
xml.elements("/kp:process/kp:activity[@name=e.attributes[“name”]]/kp:inputBindings
}

kp:process
<kp:activity name=“one”>
kp:x857</kp:x>
kp:y161</kp:y>

ErrorSchema

kp:inputBindings
ns2:ActivityInput

xsl:choose
<xsl:when
test="$map/EventData/retryEvent=‘true’">

kp:inputBindings
</kp:activity>
<kp:activity name=“two”>
kp:x857</kp:x>
kp:y161</kp:y>

ErrorSchema

kp:inputBindings
ns2:ActivityInput

xsl:choose
<xsl:when
test="$map/EventDataretryEvent=‘true’">

kp:inputBindings
</kp:activity>
kp:process

On Thu, Jan 5, 2012 at 5:08 AM, dabba dabba [email protected]
wrote:

I have an xml structure like below and would like to store the activity
name attribute as key along with complete inputBindings structure with
xml tags etc as value in a hash -

You should at least mention which XML parser you are using.

activityName = Hash.new

Following doesn’t get anything in value -

xml.elements.each(“/kp:process/kp:activity”){ |e|
@activityName[e.attributes[“name”]] =

You need to at least remove “@”. You may also have to change
attribute value extraction, depending on XML lib used.

xml.elements("/kp:process/kp:activity[@name=e.attributes[“name”]]/kp:inputBindings

}

Also, you might need to add XML namespace handling.

Cheers

robert

I am using REXML Parser.
exact code - xml=REXML::Document.new(IO.read(filename))

I got it using a different way to generate the hash structure -

xml.elements.each("/kp:process/kp:activity"){ |e|
@activityName[e.attributes[“name”]] =
xml.elements(e.elements[“child::kp:inputBindings”])
}