Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XML Validation : isschemavalid always returns 0

151352Aug 24 2005 — edited Aug 26 2005
Hello XML folks,
I have registered the schema and tried to validate. It always returns 0 (i.e invalid).

Could you please let me know what is wrong with XSD or XML

Thanks,
Parappa



SQL> DECLARE
2 doc varchar2(3800) :=
3 '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
4 <!--W3C Schema generated by XMLSpy v2005 sp1 U (http://www.xmlspy.com)-->
5 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:context="http://ibtco.com/common/exception/context" targetNamespace="http://ibtco.com/common/exception/context" elementFormDefault="qualified" attributeFormDefault="unqualified">
6 <xs:simpleType name="ContextValueType">
7 <xs:annotation>
8 <xs:documentation>data types for properties</xs:documentation>
9 </xs:annotation>
10 <xs:restriction base="xs:string">
11 <xs:enumeration value="boolean"/>
12 <xs:enumeration value="char"/>
13 <xs:enumeration value="byte"/>
14 <xs:enumeration value="int"/>
15 <xs:enumeration value="long"/>
16 <xs:enumeration value="float"/>
17 <xs:enumeration value="double"/>
18 <xs:enumeration value="decimal"/>
19 <xs:enumeration value="date"/>
20 <xs:enumeration value="time"/>
21 <xs:enumeration value="dateTime"/>
22 <xs:enumeration value="string"/>
23 </xs:restriction>
24 </xs:simpleType>
25 <xs:complexType name="ContextPropertyType">
26 <xs:annotation>
27 <xs:documentation>
28 for holding name/value pair for application data
29 </xs:documentation>
30 </xs:annotation>
31 <xs:simpleContent>
32 <xs:extension base="xs:string">
33 <xs:attribute name="Name" type="xs:Name" use="required"/>
34 <xs:attribute name="Type" type="context:ContextValueType" use="optional"/>
35 </xs:extension>
36 </xs:simpleContent>
37 </xs:complexType>
38 <xs:complexType name="ExceptionContextType">
39 <xs:annotation>
40 <xs:documentation>
41 for holding the data from applications
42 </xs:documentation>
43 </xs:annotation>
44 <xs:sequence>
45 <xs:element name="Property" type="context:ContextPropertyType" minOccurs="0" maxOccurs="unbounded"/>
46 </xs:sequence>
47 </xs:complexType>
48 <xs:element name="ExceptionContext" type="context:ExceptionContextType">
49 <xs:annotation>
50 <xs:documentation>
51 top level element exception context
52 </xs:documentation>
53 </xs:annotation>
54 </xs:element>
55 </xs:schema>';
56 BEGIN
57 dbms_xmlschema.registerSchema('http://ibtco.com/common/exception/context', doc);
58 END;
59 /

PL/SQL procedure successfully completed.

SQL> DECLARE
2
3 l_errormsgid VARCHAR2(30);
4 l_errorinfo VARCHAR2(100);
5 l_error_context CLOB; -- Error Stack
6 l_error_context_data CLOB; -- XML Context
7 l_var_xml_context VARCHAR2(4000);
8 l_var_error_stack VARCHAR2(4000);
9 l_sqlCode UTL_ERROR_LOGS.ERROR_CODE%TYPE;
10 p_ErrorMsgId NUMBER := '0';
11 p_ErrorInfo VARCHAR2(2000):= 'SUCCESS';
12 l_xml_context SYS.XMLTYPE;
13 l_count number :=0;
14 l_ret NUMBER;
15 BEGIN
16
17
18 -- Store XML in a clob
19 /*
20 l_var_xml_context := '<ExceptionContext>
21 <Property Name="Name1" Type="boolean">true</Property>
22 <Property Name="Name2" Type="string">String</Property>
23 </ExceptionContext>';
24 */
25
26 l_var_xml_context := '<?xml version="1.0" encoding="UTF-8"?>
27 <!--Sample XML file generated by XMLSpy v2005 sp1 U (http://www.xmlspy.com)-->
28 <ExceptionContext
29 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
30 xsi:schemaLocation="http://ibtco.com/common/exception/context"
31 >
32 <Property Name="Name1" Type="boolean">true</Property>
33 <Property Name="Name2" Type="string">String</Property>
34 </ExceptionContext>';
35
36 DBMS_LOB.CREATETEMPORARY
37 (
38 lob_loc => l_error_context_data,
39 cache => TRUE
40 );
41
42 DBMS_LOB.WRITE
43 (
44 lob_loc =>l_error_context_data,
45 amount => length(l_var_xml_context),
46 offset => 1,
47 buffer => l_var_xml_context
48 );
49
50 l_xml_context := XMLTYPE(l_error_context_data);
51
52
53 -- validate against XML schema
54 --l_xml_context.schemavalidate();
55 l_ret := l_xml_context.isschemavalid('"http://ibtco.com/common/exception/context"');
56 IF l_ret = 1 then
57 dbms_output.put_line('Data is valid:' || l_ret );
58 ELSE
59 dbms_output.put_line('Data is invalid:' || l_ret);
60 END IF;
61 END;
62 /
Data is invalid:0

PL/SQL procedure successfully completed.

SQL>
SQL>

Here is the script :

DECLARE
doc varchar2(3800) :=
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--W3C Schema generated by XMLSpy v2005 sp1 U (http://www.xmlspy.com)-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:context="http://ibtco.com/common/exception/context" targetNamespace="http://ibtco.com/common/exception/context" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:simpleType name="ContextValueType">
<xs:annotation>
<xs:documentation>data types for properties</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:enumeration value="boolean"/>
<xs:enumeration value="char"/>
<xs:enumeration value="byte"/>
<xs:enumeration value="int"/>
<xs:enumeration value="long"/>
<xs:enumeration value="float"/>
<xs:enumeration value="double"/>
<xs:enumeration value="decimal"/>
<xs:enumeration value="date"/>
<xs:enumeration value="time"/>
<xs:enumeration value="dateTime"/>
<xs:enumeration value="string"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="ContextPropertyType">
<xs:annotation>
<xs:documentation>
for holding name/value pair for application data
</xs:documentation>
</xs:annotation>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="Name" type="xs:Name" use="required"/>
<xs:attribute name="Type" type="context:ContextValueType" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="ExceptionContextType">
<xs:annotation>
<xs:documentation>
for holding the data from applications
</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="Property" type="context:ContextPropertyType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ExceptionContext" type="context:ExceptionContextType">
<xs:annotation>
<xs:documentation>
top level element exception context
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>';
BEGIN
dbms_xmlschema.registerSchema('http://ibtco.com/common/exception/context', doc);
END;
/


DECLARE

l_errormsgid VARCHAR2(30);
l_errorinfo VARCHAR2(100);
l_error_context CLOB; -- Error Stack
l_error_context_data CLOB; -- XML Context
l_var_xml_context VARCHAR2(4000);
l_var_error_stack VARCHAR2(4000);
l_sqlCode UTL_ERROR_LOGS.ERROR_CODE%TYPE;
p_ErrorMsgId NUMBER := '0';
p_ErrorInfo VARCHAR2(2000):= 'SUCCESS';
l_xml_context SYS.XMLTYPE;
l_count number :=0;
l_ret NUMBER;
BEGIN


-- Store XML in a clob
/*
l_var_xml_context := '<ExceptionContext>
<Property Name="Name1" Type="boolean">true</Property>
<Property Name="Name2" Type="string">String</Property>
</ExceptionContext>';
*/

l_var_xml_context := '<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSpy v2005 sp1 U (http://www.xmlspy.com)-->
<ExceptionContext
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ibtco.com/common/exception/context"
>
<Property Name="Name1" Type="boolean">true</Property>
<Property Name="Name2" Type="string">String</Property>
</ExceptionContext>';

DBMS_LOB.CREATETEMPORARY
(
lob_loc => l_error_context_data,
cache => TRUE
);

DBMS_LOB.WRITE
(
lob_loc =>l_error_context_data,
amount => length(l_var_xml_context),
offset => 1,
buffer => l_var_xml_context
);

l_xml_context := XMLTYPE(l_error_context_data);


-- validate against XML schema
--l_xml_context.schemavalidate();
l_ret := l_xml_context.isschemavalid('"http://ibtco.com/common/exception/context"');
IF l_ret = 1 then
dbms_output.put_line('Data is valid:' || l_ret );
ELSE
dbms_output.put_line('Data is invalid:' || l_ret);
END IF;
END;
/
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 23 2005
Added on Aug 24 2005
3 comments
402 views