<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: The xpath command does not work with XML prolog header lines (e.g. &amp;amp;lt;?xml version=1.0?&amp;amp;gt;. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/The-xpath-command-does-not-work-with-XML-prolog-header-lines-e-g/m-p/747451#M241824</link>
    <description>&lt;P&gt;On the bug fix for this issue, Splunk Support have come back with the following ...&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Observation &amp;amp; Findings:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Thanks for flagging this issue with us and we taken this to the development team.&lt;/LI&gt;&lt;LI&gt;We informed you that our development team is having high level discussions on the xpath command whether to deprecate it or enhance it.&lt;/LI&gt;&lt;LI&gt;Once the xpath enhancement or deprecation is done, it will be updated in the official documentation.&lt;/LI&gt;&lt;LI&gt;As this task will undergo through some pre-checks, post-checks and some approvals which might take some time.&lt;/LI&gt;&lt;/OL&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;So workarounds are the only option, for now.&lt;BR /&gt;&lt;BR /&gt;Here's a more generic regex to extract different sorts of XML declarations (note, removes CDATA entries too)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| ...
  ``` example: https://regex101.com/r/BqHeX4/3 ```
| eval xml=replace(_raw, "(?s)(\&amp;lt;[\?\!]([^\\&amp;gt;]+\&amp;gt;).+?)*(?=\&amp;lt;[^(?=\/)])(?=[a-zA-Z])*", "")   
| rex mode=sed field=_raw "s/(?s)(\&amp;lt;[\?\!]([^\\&amp;gt;]+\&amp;gt;).+?)*(?=\&amp;lt;[^(?=\/)])(?=[a-zA-Z])*//g"  ``` sed example for a props.conf SEDCMD to remove XML declarations before indexing ```
| xpath ...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;Finally, there is another bug (Splunk said they are aware) with the xpath command when it is used more than once.&amp;nbsp; Any existing multi-value fields become non multi-value fields (like a nomv command has been applied) so any mv manipulations should be done before subsequent xpath commands.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Jun 2025 02:08:18 GMT</pubDate>
    <dc:creator>yeahnah</dc:creator>
    <dc:date>2025-06-04T02:08:18Z</dc:date>
    <item>
      <title>The xpath command does not work with XML prolog header lines (e.g. &lt;?xml version="1.0"?&gt;)</title>
      <link>https://community.splunk.com/t5/Splunk-Search/The-xpath-command-does-not-work-with-XML-prolog-header-lines-e-g/m-p/711425#M240163</link>
      <description>&lt;P&gt;The &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Xpath" target="_self"&gt;xpath&lt;/A&gt; command does not work if the XML event contains valid prolog header lines (&lt;A href="https://www.w3schools.com/xml/xml_syntax.asp" target="_blank" rel="noopener"&gt;https://www.w3schools.com/xml/xml_syntax.asp&lt;/A&gt;).&lt;BR /&gt;&lt;BR /&gt;For example, this works&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="&amp;lt;Event&amp;gt;
  &amp;lt;System&amp;gt;
    &amp;lt;Provider Name='ABC'/&amp;gt;
  &amp;lt;/System&amp;gt;
&amp;lt;/Event&amp;gt;"
| xpath field=_raw outfield=raw_provider_name_attr "//Provider/@Name"
| table _raw raw_provider_name_attr&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;but, add a prolog header and it will no longer work ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="&amp;lt;?xml version=\"1.0\?&amp;gt;
&amp;lt;Event&amp;gt;
  &amp;lt;System&amp;gt;
    &amp;lt;Provider Name='ABC'/&amp;gt;
  &amp;lt;/System&amp;gt;
&amp;lt;/Event&amp;gt;"
| xpath field=_raw outfield=raw_provider_name_attr "//Provider/@Name"
| table _raw raw_provider_name_attr&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've raised a support case with Splunk about this.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2025 23:30:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/The-xpath-command-does-not-work-with-XML-prolog-header-lines-e-g/m-p/711425#M240163</guid>
      <dc:creator>yeahnah</dc:creator>
      <dc:date>2025-02-12T23:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: The xpath command does not work with XML prolog header lines (e.g. &amp;lt;?xml version=1.0?&amp;gt;.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/The-xpath-command-does-not-work-with-XML-prolog-header-lines-e-g/m-p/711426#M240164</link>
      <description>&lt;P&gt;To workaround this issue, remove the valid XML prolog headers from the event before calling the&amp;nbsp;&lt;FONT size="5"&gt;xpath&lt;/FONT&gt;&amp;nbsp;command, or use the&amp;nbsp;&lt;FONT size="5"&gt;spath&lt;/FONT&gt; command instead.&amp;nbsp; Here is a run anywhere example.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="&amp;lt;?xml version\"1.0\"?&amp;gt;
&amp;lt;Event&amp;gt;
  &amp;lt;System&amp;gt;
    &amp;lt;Provider Name='ABC'/&amp;gt;
  &amp;lt;/System&amp;gt;
&amp;lt;/Event&amp;gt;
&amp;lt;!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"&amp;gt;
&amp;lt;Event&amp;gt;
  &amp;lt;System&amp;gt;
    &amp;lt;Provider Name='EFG'/&amp;gt;
  &amp;lt;/System&amp;gt;
&amp;lt;/Event&amp;gt;
&amp;lt;?xml version\"1.0\"?&amp;gt;
&amp;lt;!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"&amp;gt;
&amp;lt;Event&amp;gt;
  &amp;lt;System&amp;gt;
    &amp;lt;Provider Name='HIJ'/&amp;gt;
  &amp;lt;/System&amp;gt;
&amp;lt;/Event&amp;gt;"
| eval xml=replace(_raw, "&amp;lt;(\?xml|!DOCTYPE).+?&amp;gt;[\r\n]*", "")
| xpath field=_raw outfield=raw_provider_name_attr "//Provider/@Name"
| xpath field=xml outfield=xml_provider_name_attr "//Provider/@Name"
| spath output=spath_provider_name_attr Event.System{2}.Provider{@Name}
| table _raw raw_provider_name_attr xml* spath*&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2025 23:27:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/The-xpath-command-does-not-work-with-XML-prolog-header-lines-e-g/m-p/711426#M240164</guid>
      <dc:creator>yeahnah</dc:creator>
      <dc:date>2025-02-12T23:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: The xpath command does not work with XML prolog header lines (e.g. &amp;lt;?xml version=1.0?&amp;gt;.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/The-xpath-command-does-not-work-with-XML-prolog-header-lines-e-g/m-p/747451#M241824</link>
      <description>&lt;P&gt;On the bug fix for this issue, Splunk Support have come back with the following ...&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Observation &amp;amp; Findings:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Thanks for flagging this issue with us and we taken this to the development team.&lt;/LI&gt;&lt;LI&gt;We informed you that our development team is having high level discussions on the xpath command whether to deprecate it or enhance it.&lt;/LI&gt;&lt;LI&gt;Once the xpath enhancement or deprecation is done, it will be updated in the official documentation.&lt;/LI&gt;&lt;LI&gt;As this task will undergo through some pre-checks, post-checks and some approvals which might take some time.&lt;/LI&gt;&lt;/OL&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;So workarounds are the only option, for now.&lt;BR /&gt;&lt;BR /&gt;Here's a more generic regex to extract different sorts of XML declarations (note, removes CDATA entries too)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| ...
  ``` example: https://regex101.com/r/BqHeX4/3 ```
| eval xml=replace(_raw, "(?s)(\&amp;lt;[\?\!]([^\\&amp;gt;]+\&amp;gt;).+?)*(?=\&amp;lt;[^(?=\/)])(?=[a-zA-Z])*", "")   
| rex mode=sed field=_raw "s/(?s)(\&amp;lt;[\?\!]([^\\&amp;gt;]+\&amp;gt;).+?)*(?=\&amp;lt;[^(?=\/)])(?=[a-zA-Z])*//g"  ``` sed example for a props.conf SEDCMD to remove XML declarations before indexing ```
| xpath ...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;Finally, there is another bug (Splunk said they are aware) with the xpath command when it is used more than once.&amp;nbsp; Any existing multi-value fields become non multi-value fields (like a nomv command has been applied) so any mv manipulations should be done before subsequent xpath commands.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jun 2025 02:08:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/The-xpath-command-does-not-work-with-XML-prolog-header-lines-e-g/m-p/747451#M241824</guid>
      <dc:creator>yeahnah</dc:creator>
      <dc:date>2025-06-04T02:08:18Z</dc:date>
    </item>
  </channel>
</rss>

