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:x 857</kp:x>
kp:y 161</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:x 857</kp:x>
kp:y 161</kp:y>
ErrorSchema
kp:inputBindings
ns2:ActivityInput
xsl:choose
<xsl:when
test="$map/EventDataretryEvent=‘true’">
…
kp:inputBindings
</kp:activity>
kp:process
dabba
January 5, 2012, 11:48pm
2
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
dabba
January 7, 2012, 7:39pm
3
I am using REXML Parser.
exact code - xml=REXML::Document.new(IO.read(filename))
dabba
January 10, 2012, 12:22am
4
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”])
}