M
Michael
I've been struggling to properly parse some XML with rexml. I will fully
admit my XML ignorance in advance. It would be easy enough to parse
this with a regular expression instead, but I would prefer to use the
right tool.
Here's a sample XML response:
<?xml version='1.0' encoding="iso-8859-1" ?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value>
<int>5</int>
</value>
</member>
<member>
<name>faultString</name>
<value>
<string>system error (nologin)</string>
</value>
</member>
</struct>
</value>
</fault>
</methodResponse>
However, I can't anything useful out of it. For instance, I've been
trying something like this:
require 'rexml/document'
file = File.new("test.xml")
xml = REXML:
ocument.new(file)
xml.elements.each { |i|
i.texts.each { |t|
puts "Class: #{t.class}"
puts "Value: #{t.value}"
puts "String: #{t.to_s}"
}
}
This doesn't print anything useful for the class. Where am I going wrong
with this? I've been digging through the documentation but I'm must not
getting it.
For what it's worth, I can parse this in perl easily enough (which
suggests to me the XML is valid):
use Data:
umper;
use XML::Simple; # AKA "XML For Idiots"
my $ref = XMLin("test.xml"); # A file containing the XML above
print Dumper $ref, "\n";
I can then use the results to figure out how to dereference $ref to pull
the error information returned by the server.
Responses to the list or the newsgroup, please, for future googlers
to find.
admit my XML ignorance in advance. It would be easy enough to parse
this with a regular expression instead, but I would prefer to use the
right tool.
Here's a sample XML response:
<?xml version='1.0' encoding="iso-8859-1" ?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value>
<int>5</int>
</value>
</member>
<member>
<name>faultString</name>
<value>
<string>system error (nologin)</string>
</value>
</member>
</struct>
</value>
</fault>
</methodResponse>
However, I can't anything useful out of it. For instance, I've been
trying something like this:
require 'rexml/document'
file = File.new("test.xml")
xml = REXML:
xml.elements.each { |i|
i.texts.each { |t|
puts "Class: #{t.class}"
puts "Value: #{t.value}"
puts "String: #{t.to_s}"
}
}
This doesn't print anything useful for the class. Where am I going wrong
with this? I've been digging through the documentation but I'm must not
getting it.
For what it's worth, I can parse this in perl easily enough (which
suggests to me the XML is valid):
use Data:
use XML::Simple; # AKA "XML For Idiots"
my $ref = XMLin("test.xml"); # A file containing the XML above
print Dumper $ref, "\n";
I can then use the results to figure out how to dereference $ref to pull
the error information returned by the server.
Responses to the list or the newsgroup, please, for future googlers
to find.