PL/SQL XML解析问题:动态命名空间下无法获取标签值
解决PL/SQL中动态命名空间XML标签取值问题
可以不用硬编码命名空间前缀或URI,通过在XPath中结合local-name()匹配标签名,忽略命名空间的影响。
修改后的SQL代码如下:
select test.test_customer_id, test.test_customer_id_2 from ( select column_value from XMLTABLE(q'~//*[local-name()='ResponseData']~' PASSING (select xmltype('<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <V2 xmlns:ns27="http://testnamespace"> <ResponseData> <CustomerData> <ns27:TestCustomerId>27295343</ns27:TestCustomerId> <ns27:TestCustomerId2>27295343</ns27:TestCustomerId2> </CustomerData> </ResponseData> </V2> </S:Body> </S:Envelope>' ) from dual))) dlcp, XMLTABLE('//CustomerData' PASSING dlcp.column_value COLUMNS test_customer_id VARCHAR2(100) PATH '*[local-name()="TestCustomerId"]', test_customer_id_2 VARCHAR2(100) PATH '*[local-name()="TestCustomerId2"]') test;
关键修改说明
- 原代码中
PATH 'TestCustomerId'无法匹配带命名空间的<ns27:TestCustomerId>,因为XPath默认仅匹配无命名空间的标签。 - 改用
PATH '*[local-name()="TestCustomerId"]'后,会匹配所有本地标签名为TestCustomerId的元素,不管它属于哪个命名空间,彻底避开命名空间变更的问题。
内容的提问来源于stack exchange,提问作者babicsp
相关产品推荐
相关产品推荐

