views:

376

answers:

6

I would like to display details of an xml error log to a user in a winforms application and am looking for the best control to do the job.

The error data contains all of the sever variables at the time that the error occurred. These have been formatted into an XML document that looks something to the effect of:

<error>
    <serverVariables>
     <item>
      <value>
     </item>
    </serverVariables>
    <queryString>
     <item name="">
      <value string=""> 
     </item>
    </queryString>  
</error>

I would like to read this data from the string that it is stored in and display it to the user via a windows form in a useful way. XML Notepad does a cool job of formatting xml, but is not really was I am looking for since I would prefer to rather display item details in a Name : string format.

Any suggestions or am I looking and a custom implementation?

[EDIT] A section of the data that needs to be displayed:

<?xml version="1.0" encoding="utf-8"?>
<error host="WIN12" type="System.Web.HttpException" message="The file '' does not exist." source="System.Web" detail="System.Web.HttpException: The file '' does not exist. at System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath) at" time="2008-09-01T07:13:08.9171250+02:00" statusCode="404">
  <serverVariables>
    <item name="ALL_HTTP">
      <value string="HTTP_CONNECTION:close HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) " />
    </item>
    <item name="AUTH_TYPE">
      <value string="" />
    </item>
    <item name="HTTPS">
      <value string="off" />
    </item>
    <item name="HTTPS_KEYSIZE">
      <value string="" />
    </item>
    <item name="HTTP_USER_AGENT">
      <value string="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)" />
    </item>
  </serverVariables>
  <queryString>
    <item name="tid">
      <value string="196" />
    </item>
  </queryString>
</error>
A: 

Could you use a browser control?

Martin
A: 

You could try using the DataGridView control. To see an example, load an XML file in DevStudio and then right-click on the XML and select "View Data Grid". You'll need to read the API documentation on the control to use it.

Skizz

Skizz
A: 

@Martin the thought of a web control had crossed my mind, but I can't believe that that is the best option. It is an option, but for me, probably the last. :)

FryHard
+1  A: 

You can transform your XML data using XSLT
Another option is to use XLinq.
If you want concrete code example provide us with sample data

EDIT: here is a sample XSLT transform for your XML file:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    <xsl:output method="text"/>
    <xsl:template match="//error/serverVariables">
      <xsl:text>Server variables:
      </xsl:text>
      <xsl:for-each select="item">
        <xsl:value-of select="@name"/>:<xsl:value-of select="value/@string"/>
        <xsl:text>
        </xsl:text>
      </xsl:for-each>
    </xsl:template>
    <xsl:template match="//error/queryString">
      <xsl:text>Query string items:
      </xsl:text>
      <xsl:for-each select="item">
        <xsl:value-of select="@name"/>:<xsl:value-of select="value/@string"/>
        <xsl:text>
        </xsl:text>
      </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

You can apply this transform using XslCompiledTransform class. It should give output like this:

Server variables:
ALL_HTTP:HTTP_CONNECTION:close HTTP_USER_AGENT:Mozilla/4.0 (compatible MSIE 6.0; Windows NT 5.1; SV1)
AUTH_TYPE:
HTTPS:off
HTTPS_KEYSIZE:
HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;S )

Query string items:
tid:196

aku
A: 

You could use a treeview control and use a recursive XLinq algorithm to put the data in there. I've done that myself with an interface allow a user to build up a custom XML representation and it worked really well.

kronoz
A: 

See XML data binding. Use Visual Studio or xsd.exe to generate DataSet or classes from XSD, then use System.Xml.Serialization.XmlSerializer if needed to turn your XML into objects/DataSet. Massage the objects. Display them in grid.

eed3si9n