You can use DBMS_XMLPARSER to parse an XML stored in a CLOB
to find whether it is well formed or not.
I have posted this code in OTN also.
SQL> set serverout on
SQL> DECLARE
2 v_clob CLOB := '<?xml version="1.0"?>
3 <ROWSET>
4 <IBSCOLYTD>
5 <ACTNOI>28004125</ACTNOI>
6 <MEMONOI>251942</MEMONOI>
7 <MEMODTEI>05-SEP-92</MEMODTEI>
8 <AMOUNTI>400</AMOUNTI>
9 <BRCDSI>513</BRCDSI>
10 <TYPEI>1</TYPEI>
11 <TRANSMONI>0</TRANSMONI>
12 </IBSCOLYTD>
13 <IBSCOLYTD>
14 <ACTNOI>28004125</ACTNOI>
15 <MEMONOI>251943</MEMONOI>
16 <MEMODTEI>04-OCT-92</MEMODTEI>
17 <AMOUNTI>400</AMOUNTI>
18 <BRCDSI>513</BRCDSI>
19 <TYPEI>1</TYPEI>
20 <TRANSMONI>0</TRANSMONI>
21 </IBSCOLYTD>
22 ';
23 l_parser DBMS_XMLPARSER.Parser;
24 BEGIN
25 -- Create a parser.
26 l_parser := DBMS_XMLPARSER.newParser;
27 -- Parse the document
28 DBMS_XMLPARSER.parseClob(l_parser, v_clob);
29 DBMS_XMLPARSER.freeParser(l_parser);
30 DBMS_OUTPUT.put_line('Parsing Success');
31 EXCEPTION
32 WHEN OTHERS THEN
33 DBMS_OUTPUT.put_line('Parsing failed');
34 DBMS_XMLPARSER.freeParser(l_parser);
35
36 END;
37 /
Parsing failed
PL/SQL procedure successfully completed.
SQL> DECLARE
2 v_clob CLOB := '<?xml version="1.0"?>
3 <ROWSET>
4 <IBSCOLYTD>
5 <ACTNOI>28004125</ACTNOI>
6 <MEMONOI>251942</MEMONOI>
7 <MEMODTEI>05-SEP-92</MEMODTEI>
8 <AMOUNTI>400</AMOUNTI>
9 <BRCDSI>513</BRCDSI>
10 <TYPEI>1</TYPEI>
11 <TRANSMONI>0</TRANSMONI>
12 </IBSCOLYTD>
13 <IBSCOLYTD>
14 <ACTNOI>28004125</ACTNOI>
15 <MEMONOI>251943</MEMONOI>
16 <MEMODTEI>04-OCT-92</MEMODTEI>
17 <AMOUNTI>400</AMOUNTI>
18 <BRCDSI>513</BRCDSI>
19 <TYPEI>1</TYPEI>
20 <TRANSMONI>0</TRANSMONI>
21 </IBSCOLYTD>
22 </ROWSET>
23 '; --The last line added to make it ok.
24 l_parser DBMS_XMLPARSER.Parser;
25 BEGIN
26 -- Create a parser.
27 l_parser := DBMS_XMLPARSER.newParser;
28 -- Parse the document
29 DBMS_XMLPARSER.parseClob(l_parser, v_clob);
30 DBMS_XMLPARSER.freeParser(l_parser);
31 DBMS_OUTPUT.put_line('Parsing Success');
32 EXCEPTION
33 WHEN OTHERS THEN
34 DBMS_OUTPUT.put_line('Parsing failed');
35 DBMS_XMLPARSER.freeParser(l_parser);
36
37 END;
38 /
Parsing Success
PL/SQL procedure successfully completed.
SQL>
No comments :
Post a Comment