Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I fail to see the problem you're having other than PostgreSQL breaking features. In the first document </p> <p>This is the expected behavior from a strict XML parser. The fact that PostgreSQL changed behavior is bad, but something we just have to deal with I guess.</p> <p>This</p> <pre><code>SELECT xpath('/a', '&lt;a s:dd="11"&gt;&lt;c&gt;test&lt;/c&gt;&lt;/a&gt;') </code></pre> <p>fails because the <code>s</code> namespace is not declared in the XML document. This works:</p> <pre><code># SELECT xpath('/a', '&lt;a xmlns:s="http://example.com" s:dd="11"&gt;&lt;c&gt;..&lt;/c&gt;&lt;/a&gt;'); xpath -------------------------------------------------- {"&lt;a xmlns:s=\"http://example.com\" s:dd=\"11\"&gt;+ &lt;c&gt;..&lt;/c&gt; + &lt;/a&gt;"} (1 row) </code></pre> <p>What you're doing here:</p> <pre><code>SELECT xpath('/a', '&lt;a xmlns:s="http://example.com" s:dd="11"&gt;&lt;c&gt;..&lt;/c&gt;&lt;/a&gt;', ARRAY[ARRAY['s', 'http://example.com']]); </code></pre> <p>is to bind the <code>s</code> namespace to <code>http://example.com</code> enabling you to run xpath expressions in that namespace. Observe:</p> <p>This is the original query but where the <code>a</code> tag is in the <code>http://example.com</code> namespace. Your query (<code>/a</code>) doesn't match any document as you're querying for <code>a</code> elements in the default namespace:</p> <pre><code># SELECT xpath('/a', '&lt;s:a xmlns:s="http://example.com" s:dd="11"&gt;&lt;c&gt;test&lt;/c&gt;&lt;/s:a&gt;'); xpath ------- {} (1 row) </code></pre> <p>This however, selects the root element:</p> <pre><code># SELECT xpath('/x:a', '&lt;s:a xmlns:s="http://example.com" s:dd="11"&gt;&lt;c&gt;..&lt;/c&gt;&lt;/s:a&gt;', ARRAY[ARRAY['x', 'http://example.com']]); xpath ---------------------------------------------------- {"&lt;s:a xmlns:s=\"http://example.com\" s:dd=\"11\"&gt;+ &lt;c&gt;test&lt;/c&gt; + &lt;/s:a&gt;"} (1 row) </code></pre> <p>Notice how <code>s</code> and <code>x</code> are bound to the same namespace <code>http://example.com</code>. Using different namespace bindings is confusing, but I just wanted to show you how it works.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload