M
Mmcolli00 Mom
Hi
I don't understand how to output the exact data that I need from my xml
document. I only need to get 2 data elements per xml segment, however I
am getting the whole xml segment. Will you show me how to do this?
<AnimalXML>
- <FID="28">
<Field FieldId="0" Field1="" Path="/Docs/Animal/Cat" Attribute="Fur"
/>
<Field FieldId="10" Field1="ACC" Path="/Docs/Animail/Dog"
Attribute="Fur" />
<Field FieldId="11" Field1="ACC_DATE" Path="/Docs/Animal/Bird"
Attribute="Feather" />
I am getting this:
<Field FieldId="11" Field1="ACC_DATE" Path="/Docs/Animal/Bird"
...
This is what I need the output to look like:
Cat Fur
Dog Fur
Bird Feather
#******************************************
require 'rexml/document'
include REXML
f = File.new("AnimalXML.xml")
doc = Document.new(f)
#below ex. outputs the whole xml segment
fields = XPath.match(doc, "//Field FieldId")
puts fields
#below ex. does same as above, shows whole xml segment
doc.elements.each("*/Field FieldId") { |element| puts
element.attribute['Path']}
I don't understand how to output the exact data that I need from my xml
document. I only need to get 2 data elements per xml segment, however I
am getting the whole xml segment. Will you show me how to do this?
<AnimalXML>
- <FID="28">
<Field FieldId="0" Field1="" Path="/Docs/Animal/Cat" Attribute="Fur"
/>
<Field FieldId="10" Field1="ACC" Path="/Docs/Animail/Dog"
Attribute="Fur" />
<Field FieldId="11" Field1="ACC_DATE" Path="/Docs/Animal/Bird"
Attribute="Feather" />
I am getting this:
<Field FieldId="11" Field1="ACC_DATE" Path="/Docs/Animal/Bird"
...
This is what I need the output to look like:
Cat Fur
Dog Fur
Bird Feather
#******************************************
require 'rexml/document'
include REXML
f = File.new("AnimalXML.xml")
doc = Document.new(f)
#below ex. outputs the whole xml segment
fields = XPath.match(doc, "//Field FieldId")
puts fields
#below ex. does same as above, shows whole xml segment
doc.elements.each("*/Field FieldId") { |element| puts
element.attribute['Path']}