I am trying to build an xml file using nokogiri in rails. The xml is of the below format.
<ServiceIncident>
<Incident>
<Abstract>linux_bpac_endpoint_scan_v01</Abstract>
<Description>host=endpoint01.t00.com</Description>
<FlexFields>
<FlexField mappedTo="event_class">1</FlexField>
<FlexField mappedTo="ITEM">t00-bpac:endpoint01.t00.com:linux_bpac_endpoint_scan_v01</FlexField>
<FlexField mappedTo="sr_params">{"host":"endpoint01.t00.com"}</FlexField>
<FlexField mappedTo="sr_id">{"REQUEST_ID":"100682"}</FlexField>
<FlexField mappedTo="sr_tool">bpac</FlexField>
<FlexField mappedTo="service_state">1</FlexField>
<FlexField mappedTo="host_state">1</FlexField>
<FlexField mappedTo="service_type">SR</FlexField>
</FlexFields>
</Incident>
</ServiceIncident>```
I am unable to generete FlexField. I am trying the below code.
require 'nokogiri'
builder = Nokogiri::XML::Builder.new do |xml|
xml.ServiceIncident {
xml.Incident {
xml.FlexFields {
xml.FlexField("mappedTo" => "event_class") { '1' }
}
}
}
end
puts builder.to_xml
and this is what I get.
<?xml version="1.0"?>
<ServiceIncident>
<Incident>
<FlexFields>
<FlexField mappedTo="event_class"/>
</FlexFields>
</Incident>
</ServiceIncident>
I am not able generate the value after mappedTo field. Could you please suggest what needs to be updated in the code so that the xml is generated in the correct format.