I have a database in Postgresql where I put some documents written in xml. I want to search twrough them using XPath, but my code is not working. The document are like this:
<?xml version="1.0" standalone="yes"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
....
<revisionDesc>
<listChange>
<change when="2017-01-11+01:00" who="person"/>
</listChange>
</revisionDesc>
</teiHeader>
...
</TEI>
I'm trying to get the when attribute of the change element. My code so far:
SELECT
xpath('TEI/n:teiHeader/n:revisionDesc/n:listChange/n:change[@when]/text()',
xml_document , '{{n,http://www.tei-c.org/ns/1.0}}')
FROM xml_table where xml_id = 5;
It gives me empty result like this: {} and I don't understand why
TEIelement is also in default namespace. Use prefix for it as well :n:TEI/...... 2.changeelement doesn't have inner text so/text()won't find anything, and I don't know what you actually want to get fromchangeelement/text()with/@when/to denote thatn:TEIis you root element -- or ommitn:TEIcompletely, becausexpath()will search for results relative to the root element (inxpathterms, that is the current node).