ELMAH XML Request Field

In the ELMAH_Error table, the nText field is used to store the error record. I found that adding an XML type field; then adding this new field to the INSERT SPROC statement that populates the field; I could better use the ELMAH output.

Now I would like to learn how to request specific values ​​of elements in this XML field. The document is structured as:

<error [...]>
  <serverVariables>
    <item name="ALL_HTTP">
      <value string="..." />
    </item>
    <item name="ALL_RAW">
      <value string="..." />
    </item>
    .
    .
    .
  </serverVariables>
</error>

I need to be able to query the value of certain elements below.

So, I look at an example from article 15seconds.com :

SELECT MyXml.value('(/root/product[@id="304"]/name)[1]', 'nvarchar(30)')

and trying to match these values ​​with my field structure, but I can’t. For instance.

select top 10 RealXML.value('(/error/serverVariables[@id="REMOTE_HOST"]/name)[0]', 'nvarchar(30)') 

where REMOTE_HOST is formatted:

<item name="REMOTE_HOST">
  <value string="55.55.55.55" />
</item>

much appreciated

+3
source share
1

:

select top 10 RealXML.value('(/error/serverVariables/item[@name="REMOTE_HOST"]/value/@string)[1]', 'nvarchar(30)') 

, :

DECLARE @xml XML  = '
<error>
  <serverVariables>
    <item name="ALL_HTTP">
      <value string="..." />
    </item>
    <item name="ALL_RAW">
      <value string="..." />
    </item>
<item name="REMOTE_HOST">
  <value string="55.55.55.55" />
</item>
  </serverVariables>
</error>
'
SELECT @xml.value('(/error/serverVariables/item[@name="REMOTE_HOST"]/value/@string)[1]','nvarchar(30)') 
+4

Source: https://habr.com/ru/post/1775623/


All Articles