我想将以下XML结构反序列化为PL / SQL对象类型:
<ProcessingInfo>
<MrwNumber>000001</MrwNumber>
<Station SerialNumber="nice-Attribute">Hello</Station>
</ProcessingInfo>
此XML的特殊之处:元素<Station>
具有属性SerialNumber
和实际的text()值Hello
。
如何定义类型以将XML反序列化为对象类型?
对于XML结构,我定义了以下类型:
CREATE OR REPLACE TYPE station_t FORCE AS OBJECT (
"@SerialNumber" VARCHAR2(100 CHAR)
);
CREATE OR REPLACE TYPE processingInfo_t FORCE AS OBJECT (
"MrwNumber" VARCHAR2(255)
, "Station" station_t
);
这是我的执行逻辑:
DECLARE
l_obj processingInfo_t;
l_xml XMLTYPE;
BEGIN
l_xml := xmltype(
'<ProcessingInfo>
<MrwNumber>000001</MrwNumber>
<Station SerialNumber="nice-Attribute">Hello</Station>
</ProcessingInfo>');
l_xml.toObject(l_obj);
END;
错误:
ORA-19031: XML element or attribute text does not match any in type DEMOGRAPHIC.STATION_T
ORA-06512: at "SYS.XMLTYPE", line 196
ORA-06512: at line 11
19031. 00000 - "XML element or attribute %s does not match any in type %s.%s"
*Cause: The passed in XML tag does not match any in the object type
*Action: Pass a valid canonical XML that can map to the given object type
我知道station_t
对象中缺少某些内容,因为将提供实际的text(),但未在类型中定义它。但我确实知道了。
另一个问题是,当在对象级别成功进行序列化时,如何访问属性值?
其他:当我从<Station>
中删除text()= Hello 时,序列化似乎有效:
DECLARE
l_obj processingInfo_t;
l_xml XMLTYPE;
BEGIN
l_xml := xmltype(
'<ProcessingInfo>
<MrwNumber>000001</MrwNumber>
<Station SerialNumber="nice-Attribute"></Station>
</ProcessingInfo>');
l_xml.toObject(l_obj);
END;