<?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: Using the xpath command with namespace declarations (xmlns='mynamespace') in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-the-xpath-command-with-namespace-declarations-xmlns/m-p/711428#M240165</link>
    <description>&lt;P&gt;Created an answer with workaround for the xpath and prolog header line issue here:&amp;nbsp;&lt;BR /&gt;&lt;A href="https://community.splunk.com/t5/Splunk-Search/The-xpath-command-does-not-work-with-XML-prolog-header-lines-e-g/td-p/711425" target="_blank"&gt;https://community.splunk.com/t5/Splunk-Search/The-xpath-command-does-not-work-with-XML-prolog-header-lines-e-g/td-p/711425&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Feb 2025 23:35:54 GMT</pubDate>
    <dc:creator>yeahnah</dc:creator>
    <dc:date>2025-02-12T23:35:54Z</dc:date>
    <item>
      <title>Using the xpath command with namespace declarations (xmlns='mynamespace')</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-xpath-command-with-namespace-declarations-xmlns/m-p/711420#M240160</link>
      <description>&lt;P&gt;Splunk's &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Xpath" target="_self"&gt;xpath&lt;/A&gt; documentation does not show any examples on how to use the &lt;FONT size="5"&gt;xpath&lt;/FONT&gt; command if the XML contains namespace declarations, e.g. &amp;lt;event xmlns='mynamespace'&amp;gt; or &amp;lt;prefix:Event xmlns:prefix='mynamespace'&amp;gt;.&amp;nbsp; &amp;nbsp;The xpath command will not extract any results unless the event is modified and the namespace declaration(s) removed from the event first.&amp;nbsp; Probably the most used workaround would be using the &lt;FONT size="5"&gt;spath&lt;/FONT&gt; command instead.&lt;BR /&gt;&lt;BR /&gt;However, after some googling about the path syntax for XPath you find there is a special&amp;nbsp;local-name() notation that can be used so the namespace declarations are ignored during parsing.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2025 22:24:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-xpath-command-with-namespace-declarations-xmlns/m-p/711420#M240160</guid>
      <dc:creator>yeahnah</dc:creator>
      <dc:date>2025-02-12T22:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: Using the xpath command with namespace declarations (xmlns='mynamespace')</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-xpath-command-with-namespace-declarations-xmlns/m-p/711422#M240161</link>
      <description>&lt;P&gt;The following run anywhere search demonstrates how to use local-name() notation with the xpath command to extract field values (note, the xmlkv command works well, but not on node attribute values, e.g. Name=&amp;lt;value&amp;gt; used in the example below.&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='A'/&amp;gt;
  &amp;lt;/System&amp;gt;
&amp;lt;/Event&amp;gt;
&amp;lt;Event xmlns='nameSpace'&amp;gt;
  &amp;lt;System xmlns='anotherNameSpace'&amp;gt;
    &amp;lt;Provider Name='B'/&amp;gt;
  &amp;lt;/System&amp;gt;
&amp;lt;/Event&amp;gt;
&amp;lt;Event xmlns='nameSpace'&amp;gt;
  &amp;lt;System a='attribute'&amp;gt;
    &amp;lt;Provider Name='C'/&amp;gt;
  &amp;lt;/System&amp;gt;
&amp;lt;/Event&amp;gt;
&amp;lt;e:Event xmlns:e='prefixed/nameSpace'&amp;gt;
  &amp;lt;s:System xmlns:s='moreNameSpace'&amp;gt;
    &amp;lt;Provider Name='D'&amp;gt;X&amp;lt;/Provider&amp;gt;
    &amp;lt;Provider Name='E'&amp;gt;Z&amp;lt;/Provider&amp;gt;
  &amp;lt;/s:System&amp;gt;
&amp;lt;/e:Event&amp;gt;"
  ``` examples of using xpath with XML that contains namespace declarations ```
| xpath outfield=name_no_ns "//Provider/@Name"
| xpath outfield=name_with_ns1 "//*[local-name()='Provider']/@Name"
| xpath outfield=name_with_ns2 "./*/*[local-name()='System'][@a='attribute']/*[local-name()='Provider']/@Name"
| xpath outfield=name_with_ns3 "/*[name()='e:Event' and namespace-uri()='prefixed/nameSpace']/*[name()='s:System']/*[name()='Provider']/@Name"
| xpath outfield=value_with_ns1 "/*[name()='e:Event' and namespace-uri()='prefixed/nameSpace']/*[name()='s:System']/*[name()='Provider']"
| xpath outfield=value_with_ns2 "/*[name()='e:Event' and namespace-uri()='prefixed/nameSpace']/*[name()='s:System']/*[name()='Provider'][@Name='E']"
  ``` spath also provides another method to extract XML values ```
| spath output=spath_attribute path=Event.System{2}.Provider{@Name}   
| spath output=spath_value path=e:Event.s:System.Provider&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;I raised this with the Splunk documentation team and hopefully they'll add an extended example like the one above to demonstrate namespace support when using xpath.&lt;BR /&gt;&lt;BR /&gt;One last thing, there is currently a bug in the xpath command and if the XML has prolog declarations (e.g. &amp;lt;?xml version=1.0?&amp;gt; or &amp;lt;!DOCTYPE ....&amp;gt; then xpath does not work.&amp;nbsp; I've raised a support case about this.&amp;nbsp; A workaround is modifying the event and removing the prolog declarations, or using spath command instead.&lt;BR /&gt;&lt;BR /&gt;Hope this helps anyone else who experiences this issue.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Mar 2025 22:40:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-xpath-command-with-namespace-declarations-xmlns/m-p/711422#M240161</guid>
      <dc:creator>yeahnah</dc:creator>
      <dc:date>2025-03-23T22:40:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using the xpath command with namespace declarations (xmlns='mynamespace')</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-the-xpath-command-with-namespace-declarations-xmlns/m-p/711428#M240165</link>
      <description>&lt;P&gt;Created an answer with workaround for the xpath and prolog header line issue here:&amp;nbsp;&lt;BR /&gt;&lt;A href="https://community.splunk.com/t5/Splunk-Search/The-xpath-command-does-not-work-with-XML-prolog-header-lines-e-g/td-p/711425" target="_blank"&gt;https://community.splunk.com/t5/Splunk-Search/The-xpath-command-does-not-work-with-XML-prolog-header-lines-e-g/td-p/711425&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2025 23:35:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-the-xpath-command-with-namespace-declarations-xmlns/m-p/711428#M240165</guid>
      <dc:creator>yeahnah</dc:creator>
      <dc:date>2025-02-12T23:35:54Z</dc:date>
    </item>
  </channel>
</rss>

