【发布时间】:2013-04-08 01:26:15
【问题描述】:
下面是我的 Postgres 表中的列响应。我想从我的 Postgres 数据库中的所有行中提取状态。状态可能是不同大小的,例如SUCCESS,所以我不想使用 substring 函数。有办法吗?
<?xml version="1.0" ?><response><status>ERROR_MISSING_DATA</status><responseType>COUNTRY_MISSING</responseType><country_info>USA</country_info><phone_country_code>1234</phone_country_code></response>
所以我的表结构是这样的
Column | Type | Modifiers
-------------+-----------------------------+----------------------------------------------------------
id | bigint | not null default nextval('events_id_seq'::regclass)
hostname | text | not null
time | timestamp without time zone | not null
trn_type | text |
db_ret_code | text |
request | text |
response | text |
wait_time | text |
我想从每个请求中提取状态。我该怎么做?
下面是示例行。并假设表名 abc_events
id | 1870667
hostname | abcd.local
time | 2013-04-16 00:00:23.861
trn_type | A
request | <?xml version="1.0" ?><response><status>ERROR_MISSING_DATA</status><responseType>COUNTRY_MISSING</responseType><country_info>USA</country_info><phone_country_code>1234</phone_country_code></response>
response | <?xml version="1.0" ?><response><status>ERROR_MISSING_DATA</status><responseType>COUNTRY_MISSING</responseType><country_info>USA</country_info><phone_country_code>1234</phone_country_code></response>
【问题讨论】:
-
request 有 xml 请求,response 有 xml 响应。我上面显示的 xml 是响应的一个示例。本质上,我试图从每个 xml 响应行中提取状态标记。
标签: xml postgresql xpath casting xml-parsing