Rexml

Hi all, please can someone help , I am almost at the point of losing it !
:slight_smile:

I am writing a drb application that will recieve an XML ‘envelope’ that
identifies a request, the object type to instantiate and the criteria to
apply to the objects constructor. I am having trouble trying to traverse and
extract the xml data elements

Please could someone help

Here is the request xml

<?xml version="1.0" encoding="ISO-8859-1"?> 1 2 1,2,3,4,5 31/12/2001 31/12/2002

the above is assigned to the xmlSent variable
the criteria is where I cannot get it to work

what I want to do is get all the elements for and add them into
the hash
for example:

object[‘criteria’][‘market’] = '1’
object[‘criteria’][‘benchmark’] = '1’
object[‘criteria’][‘manager’] = ‘1,2,3,4,5’

the elements within are dynamic so I dont want to hardcode it

rq = (Document.new xmlSent).root

	#at this point in time we handle a single xml request
	#if the entity has 1 'record' then process
	if rq.elements.size == 1 then     
		
		object['type'] =

rq.elements["//request"].attributes[‘type’]
object[‘value’] =
rq.elements["//request"].attributes[‘value’]
object[‘criteria’] = []

rq.elements.each_element_with_text("//request[1]/criteria") { |element|

from here on I have tried everything, the problem is how to loop

criteria and add to hash including the elements tag name ie =
object[‘criteria’][‘market’]

Any help would be great !!!

Graeme Matthew
Analyst Programmer
Mercer Investment Consulting
Level 29, 101 Collins Street, Melbourne, VIC, 3001, Australia
Tel - 61 3 9245 5352 Fax - 61 3 9245 5330
visit http://www.merceric.com

···

__


This e-mail and any attachments may be confidential or legally privileged.
If you received this message in error or are not the intended recipient, you
should destroy the e-mail message and any attachments or copies, and you are
prohibited from retaining, distributing, disclosing or using any information
contained herein. Please inform us of the erroneous delivery by return
e-mail.

Thank you for your cooperation.


ec03/04

Hi,

···

From: “Matthew, Graeme” Graeme.Matthew@mercer.com
Subject: REXML
Date: Wed, 30 Oct 2002 12:02:02 +0900
Message-ID: AFB901DF1A6CD411A3AD00D0B781F8E5049CA112@wmelntms01.au.wmmercer.com

Here is the request xml

<?xml version="1.0" encoding="ISO-8859-1"?> 1 2 1,2,3,4,5 31/12/2001 31/12/2002

the above is assigned to the xmlSent variable
the criteria is where I cannot get it to work

what I want to do is get all the elements for and add them into
the hash
for example:

object[‘criteria’][‘market’] = ‘1’
object[‘criteria’][‘benchmark’] = ‘1’
object[‘criteria’][‘manager’] = ‘1,2,3,4,5’

What about this?

rq = (Document.new xmlSent).root
if rq.elements.size == 1 then
object[‘type’] = rq.attributes[‘type’]
object[‘value’] = rq.attributes[‘value’]
object[‘criteria’] = {}
rq.elements[‘criteria’].each_element do |element|
object[‘criteria’][element.name] = element.text
end
end

Regards,

Kouhei Sutou
kou@cneti.net