ORA-31011:尝试获取XML输出时XML解析失败

时间:2019-01-29 00:11:34

标签: xml oracle oracle11g

尝试从CLOB XML列获取值时,出现以下错误:

ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00601: Invalid token in: '/l-analysis/vehicle/odometer-reading/reading value/text()'
31011. 00000 -  "XML parsing failed"
*Cause:    XML parser returned an error while trying to parse the document.
*Action:   Check if the document to be parsed is valid.

我有以下XML输出:

<?xml version="1.0" encoding="UTF-8"?>
<l-analysis>
   <vehicle>
      <make>SAAB</make>
      <model>9000 CSI</model>
      <body-style code="SL">Saloon</body-style>
      <vehicle-type code="7">Passenger car/van</vehicle-type>
      <odometer-reading latest="true">
         <reading value="154267213">154267213</reading>
         <reading-date value="2006-07-17">17-Jul-2006</reading-date>
      </odometer-reading>
   </vehicle>
</l-analysis>

当尝试获取reading value值时,我正在运行以下查询:

select XMLTYPE(xml_data).EXTRACT('/l-analysis/vehicle/odometer-reading/reading value/text()').getStringVal() AS XML FROM lm

我认为错误是由于reading value包含空格? “造成另一个没有空格的XML列起作用的原因。

我该如何工作?

1 个答案:

答案 0 :(得分:0)

valuereading的属性,而不是其文本。要寻址节点的属性,请使用@<attribute name>

SELECT xmltype(xml_data).extract('/l-analysis/vehicle/odometer-reading/reading/@value').getstringval() AS xml
       FROM lm;