A
Andrew Cox
Is it possible to create an XmlMarkup object and then populate the
nodes within another method? What I'm trying to do is create an
XmlMarkup object, start it off .... and then add nodes to it in
another method. Here's the basic code (that isn't exactly working).=20
The log_results method will be called from another location. What I
want the final result to look like is something like:
<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<results>
<result testcase=3D"test_a">
<status>PASSED</status>
</result>
<result testcase=3D"test_b">
<status>FAILED</status>
</result>
</results>
What I've been able to do is attach the internal <result> nodes to the
@xml variable, but I can't get them inside a containing <results>
node. In the code below, @results does have all of the XML in it, but
I can't figure out how to stick it into the @xml object. Is this even
possible?
The initialize method is called first (obviously) and the log_results
method is called several times from another class and then finally the
end_log method is called.
=3D=3D
def initialize(fileName, logsToKeep, maxLogSize, xmlFileName )
@logfile =3D File.new(xmlFileName, "w")
@xml =3D XmlMarkup.newtarget=3D>@logfile, :indent=3D>2)
@xml.instruct! #insert processing instruction
@results =3D XmlMarkup.new
end
def log_results(name, input, expected, test_status)
r =3D XmlMarkup.newtarget=3D>@results, :indent=3D>2)
r.resulttestcase =3D> name) do
r.status(test_status)
end #results tag
end #log_results
def end_log
@xml.results do
@results
end
@logfile.close
end #end_log
=3D=3D
Drew Cox
nodes within another method? What I'm trying to do is create an
XmlMarkup object, start it off .... and then add nodes to it in
another method. Here's the basic code (that isn't exactly working).=20
The log_results method will be called from another location. What I
want the final result to look like is something like:
<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<results>
<result testcase=3D"test_a">
<status>PASSED</status>
</result>
<result testcase=3D"test_b">
<status>FAILED</status>
</result>
</results>
What I've been able to do is attach the internal <result> nodes to the
@xml variable, but I can't get them inside a containing <results>
node. In the code below, @results does have all of the XML in it, but
I can't figure out how to stick it into the @xml object. Is this even
possible?
The initialize method is called first (obviously) and the log_results
method is called several times from another class and then finally the
end_log method is called.
=3D=3D
def initialize(fileName, logsToKeep, maxLogSize, xmlFileName )
@logfile =3D File.new(xmlFileName, "w")
@xml =3D XmlMarkup.newtarget=3D>@logfile, :indent=3D>2)
@xml.instruct! #insert processing instruction
@results =3D XmlMarkup.new
end
def log_results(name, input, expected, test_status)
r =3D XmlMarkup.newtarget=3D>@results, :indent=3D>2)
r.resulttestcase =3D> name) do
r.status(test_status)
end #results tag
end #log_results
def end_log
@xml.results do
@results
end
@logfile.close
end #end_log
=3D=3D
Drew Cox