Is it possible to write XML to the log Report?

Ask general questions here.
User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Is it possible to write XML to the log Report?

Post by Ciege » Thu Aug 19, 2010 12:01 am

I am doing some API testing of out AUT and the result of an API call is an XML string. I can write that string out to an XML file then put a link in the log to the XML file to open it in another browser or tab or notepad etc...
However, I was wondering if it is possible to actually embed the resulting XML within the Ranorex log file itself.
When I do a report.info(XMLText) and try to open the log I get an error that the XML Page (the log file) cannot be displayed.

Sooo... Is it possible to embed XML in the Ranorex log file?

Thanks!
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Is it possible to write XML to the log Report?

Post by Support Team » Thu Aug 19, 2010 1:12 pm

Yes, it is possible to embed XML or HTML into the Ranorex report using the Report.LogHtml method.
Ciege wrote:When I do a report.info(XMLText) and try to open the log I get an error that the XML Page (the log file) cannot be displayed.
That's most probably because messages passed to the Report Log, Info, Warn ... methods get escaped. If you don't want the message to be escaped, use the Report.LogHtml method.

Regards,
Alex
Ranorex Team
.
Image

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Is it possible to write XML to the log Report?

Post by Ciege » Thu Aug 19, 2010 3:59 pm

OK, I have been using LogHTML to put the link to the XML in the log file. I switched the LogHTML to put the actual XML text. However, it doesn't work as expected (or as I had hoped).

Here is an example XML file result from my API (it comes back unformatted from the API as a string):

Code: Select all

<?xml version="1.0" encoding="utf-8" standalone="yes"?><HD><Timestamp>2010-08-19T14:47:01</Timestamp><Jobs><Job Code="Training Job" Create="false"><Insert><Records><Record Type="CostItem" Success="true"><UID>f8528f39d671471da32a61ff2ae2df97</UID><ObjectRef /><Descriptor>Cost Item '25'</Descriptor></Record></Records></Insert></Job></Jobs></HD>
When I write the file from code and put a link to it in the log and open it from the log I see all XML data. However, when I send that same string directly to the log using LogHTML I only see the data that is in the XML elements:

Code: Select all

2010-08-19T14:47:01f8528f39d671471da32a61ff2ae2df97Cost Item '25'
What I want to see in the log is all the elements, data and markup tags that is within the XML since I need to verify items there as well as just the values from within the elements.

Thanks...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Is it possible to write XML to the log Report?

Post by Support Team » Thu Aug 19, 2010 10:46 pm

I'm not sure that I understand what you really want to see in the final XML or the Ranorex ReportViewer. To make things a little clearer:

When you use the Report.Log, Info, Warn ... methods, the message you pass to that method will be enclosed in a CDATA section in the rxlog file. Characters in the message that must not appear in a CDATA section will be escaped. So the actual text in the rxlog file might be a little different to the text you passed to the method, but the text rendered/shown by the Ranorex ReportViewer (or any web browser if you rename the file extension to "xml") will exactly be your XML text.

In contrast, when you use the Report.LogHtml method, the message will be placed directly into the final Ranorex report XML without any escaping or further processing. As the default RanorexReport.xsl does not know what to do with the XML tags in your XML text, the text displayed by the ReportViewer (or web browser) will just be the inner text of the individual XML tags (the text enclosed by '<>' will be ignored). You need to extend the XSL stylesheet to handle the XML tags in your XML text if you want to show the XML text in a special way.

I used the XML text from your last post for the following example:
string xml = @"<?xml version=""1.0"" encoding=""utf-8"" ... </HD>";
Report.LogHtml(ReportLevel.Info, "My Category", xml);
Report.Info(xml);
The above code will produce the following report displayed by the Ranorex ReportViewer:
Report.png
Report.png (22.6 KiB) Viewed 1555 times
If you want to customize the XSL stylesheet, please have a look at my recent blog:
http://www.ranorex.com/blog/customizing-ranorex-reports

Regards,
Alex
Ranorex Team
.
Image

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Is it possible to write XML to the log Report?

Post by Ciege » Thu Aug 19, 2010 11:03 pm

OK, this is what I have in code for reporting:

Code: Select all

Report.LogHtml(ReportLevel.Failure, "<a href=\"" + strSaveFile + "\">HDAPI Response XML.</a>");
Report.LogHtml(ReportLevel.Failure, strHDAPIResponse);
In the log I get
Line 1: a link to the XML response file I wrote from strHDAPIResponse
Line 2: this text: 2010-08-19T14:47:01f8528f39d671471da32a61ff2ae2df97Cost Item '25'

if I add the line:

Code: Select all

Report.Failure(strHDAPIResponse);
When I try to open the XML log file IE displays this messge:

Code: Select all

The XML page cannot be displayed 
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later. 


--------------------------------------------------------------------------------

End tag 'Error' does not match the start tag 'message'. Error processing resource 'file:///C:/Temp/Report/2010_8_19___14_54...

<![CDATA[<?xml version="1.0" encoding="utf-8" standalone="yes"?><HD><Timestamp>2010-08-19T21:55:01</...


It's really not that big of a deal. I just don't understand why you are able to get the actual text of the XML string in the log, but when I put the text in the log I get the above error.

No worries, I've moved on...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: Is it possible to write XML to the log Report?

Post by artur_gadomski » Fri Aug 20, 2010 6:30 am

Did you try:
Report.Failure(strHDAPIResponse);

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Is it possible to write XML to the log Report?

Post by Support Team » Fri Aug 20, 2010 8:28 am

Ciege wrote: I just don't understand why you are able to get the actual text of the XML string in the log, but when I put the text in the log I get the above error.
When you use Report.Log or Report.Info (or Report.Failure as artur_gadomski suggested - all methods do the same, just use other log levels) instead of Report.LogHtml, the XML text should appear in the ReportViewer or browser like in the example I posted...

Regards,
Alex
Ranorex Team
.
Image