Dashboards & Visualizations

Escape < and > in the xml of dashboards

chris
Motivator

Hi

I got the following error when I tried to save a dashboard after editing its xml:

Encountered the following error while trying to update: In handler 'views': Not valid XML: <view template="dashboard.html....

< and > characters are part of my search String because I'm using the rex search command

..
<module name="HiddenSearch" autoRun="True">
  <param name="search">| savedsearch "Mysearch" | where isnotnull(Resource) | rex "r> (\[.*\] )*(?<Reason>.*)$" | fields host,hostname,Resource,Reason</param>
..
.

How do those characters have to be escaped?

Tags (2)
1 Solution

gkanapathy
Splunk Employee
Splunk Employee

There are two ways:

  • Use &lt; for < and &gt; for >. You should also use &amp; for any & and some people like to use &quot; for ".
  • Enclose the entire search string in a CDATA tag: `(?.)" | stats count ]]>'

I personally think that it's a lot clearer to just use CDATA so your search query is readable:

 <module name="HiddenSearch" autoRun="True">
    <param name="search"><![CDATA[
      | savedsearch "Mysearch" | where isnotnull(Resource) | rex "r> (\[.*\] )*(?<Reason>.*)$" | fields host,hostname,Resource,Reason
    ]]></param>
    ...
 ...
 ...

View solution in original post

gkanapathy
Splunk Employee
Splunk Employee

There are two ways:

  • Use &lt; for < and &gt; for >. You should also use &amp; for any & and some people like to use &quot; for ".
  • Enclose the entire search string in a CDATA tag: `(?.)" | stats count ]]>'

I personally think that it's a lot clearer to just use CDATA so your search query is readable:

 <module name="HiddenSearch" autoRun="True">
    <param name="search"><![CDATA[
      | savedsearch "Mysearch" | where isnotnull(Resource) | rex "r> (\[.*\] )*(?<Reason>.*)$" | fields host,hostname,Resource,Reason
    ]]></param>
    ...
 ...
 ...
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...