Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgres XML XPath返回无效的XPath表达式_Xml_Postgresql_Xpath - Fatal编程技术网

Postgres XML XPath返回无效的XPath表达式

Postgres XML XPath返回无效的XPath表达式,xml,postgresql,xpath,Xml,Postgresql,Xpath,晚上好, 我一直在尝试用xml数据查询一个表。该表的字段是report\u id(int)和xml\u document(xml) xml文档的构建方式如下: <document> <type>INVESTMENT_REQUEST</type> <cro> <userId>1</userId> <surname>SUR1</surname> <name>NAM1&l

晚上好,

我一直在尝试用xml数据查询一个表。该表的字段是report\u id(int)和xml\u document(xml)

xml文档的构建方式如下:

<document>
<type>INVESTMENT_REQUEST</type>
<cro>
    <userId>1</userId>
    <surname>SUR1</surname>
    <name>NAM1</name>
    <phone>8563</phone>
</cro>
<ma>
    <userId>10</userId>
    <surname>SUR10</surname>
    <name>NAM10</name>
    <phone>6763</phone>
</ma>
<customer>
    <customer_ssn>14</customer_ssn>
    <surname>CSUR2</surname>
    <name>CNAME2</name>
    <birthdate>1985-10-10</birthdate>
    <account_date_opened>2016-05-09</account_date_opened>
    <investment_profiles>
        <investment_profile>
            <profile>4</profile>
            <date_profiled>2016-05-09</date_profiled>
        </investment_profile>
            <investment_profile>
            <profile>3</profile><date_profiled>2017-05-09</date_profiled>
        </investment_profile>
            <investment_profile>
            <profile>3</profile><date_profiled>2017-01-09</date_profiled>
        </investment_profile>
    </investment_profiles>
</customer>
<text>Customer is not averse to risks, and has a huge portfolio of investments.Please advise</text>
</document>
但是,这不起作用,它返回一个无效的XPATH表达式。有些东西我不明白,我也不明白它是什么。我已经一个字母一个字母地跟着这个例子

如果在不使用()的情况下运行命令

它返回:

<customer_ssn>12</customer_ssn>
<customer_ssn>13</customer_ssn>
<customer_ssn>14</customer_ssn>

没有名为
customer\u ssn
的函数,而且在XPath 1.0的路径步骤中只能调用节点测试函数,因此将不接受
customer\u ssn()
。也就是说,要返回
customer\ssn
中的文本节点,您应该添加节点测试
text()

//customer/customer_ssn/text()

没有名为
customer\u ssn
的函数,而且在XPath 1.0的路径步骤中只能调用节点测试函数,因此将不接受
customer\u ssn()
。也就是说,要返回
customer\ssn
中的文本节点,您应该添加节点测试
text()

//customer/customer_ssn/text()
但我还是发现了一个错误:

    SELECT * FROM consultation_report WHERE (xpath('//document/customer/customer_ssn()',xml_document))[1]::text = '14'
从咨询报告中选择*,其中(xpath('//document/customer/customer\u ssn()',xml\u document))[1]::text= ‘14’

xpath表达式中缺少
text()
函数:

SELECT * 
FROM consultation_report 
WHERE (xpath('//document/customer/customer_ssn/text()',xml_document))[1]::text = '14'
但我还是发现了一个错误:

    SELECT * FROM consultation_report WHERE (xpath('//document/customer/customer_ssn()',xml_document))[1]::text = '14'
从咨询报告中选择*,其中(xpath('//document/customer/customer\u ssn()',xml\u document))[1]::text= ‘14’

xpath表达式中缺少
text()
函数:

SELECT * 
FROM consultation_report 
WHERE (xpath('//document/customer/customer_ssn/text()',xml_document))[1]::text = '14'

我看到的示例称为实际属性文本(,所以我的想法完全错了!非常感谢,非常有用!我看到的示例称为实际属性文本(,所以我的想法完全错了!非常感谢,非常有魅力!谢谢你的回答,你确实是对的。但是我只能接受1个答案,我会选择@har07,因为他之前解释了问题所在。谢谢你的回答,你确实是对的。但是我只能接受1个答案,我会选择@har07因为他很早就开始解释问题所在。