Problems with XMLType and namespace
117914Jun 12 2006 — edited Jul 26 2006Dear subscribers:
I have been using XMLType successfully with simple XMLs - without namespaces. Now I must handle messages with "xmlns" and it seems XMLType is failing.
I tested the following XML, extracted from w3c.org examples:
<?xml version="1.0"?>
<bk:book xmlns:bk=''urn:loc.gov:books''
xmlns:isbn=''urn:ISBN:0-395-36341-6''>
<bk:title>Cheaper by the Dozen</bk:title>
<isbn:number>1568491379</isbn:number>
</bk:book>
The result of xmlt.getRootElement() is book.
However, the use of xmlt.extract( 'book' ) returns an empty object:
xmlt1 := xmlt.extract( 'book' );
dbms_output.put_line( 'StringVal: ' || xmlt1.getStringVal() );
ORA-30625: method dispatch on NULL SELF argument is disallowed
The following usages also raise errors:
xmlt1 := xmlt.extract( 'bk:book' );
ORA-31011: XML parsing failed ORA-19202: Error occurred in XML processing LPX-00601: Invalid token in: 'bk:book' ORA-06512: at "SYS.XMLTYPE", line 111
xmlt1 := xmlt.extract( 'bk::book' );
ORA-31011: XML parsing failed ORA-19202: Error occurred in XML processing LPX-00601: Invalid token in: 'bk::book' ORA-06512: at "SYS.XMLTYPE", line 111
xmlt1 := xmlt.extract( 'book', 'bk' );
ORA-31013: Invalid XPATH expression ORA-06512: at "SYS.XMLTYPE", line 119
I am using Oracle version 10.2.0.1.0. Had someone also faced this problem?
The code I used to test is at the end of this message.
Thanks in advance
====================================
DECLARE
xml varchar2(32000);
xmlt XMLType;
xmlt1 XMLType;
root varchar2(3000);
BEGIN
--Example from w3c.org
xml := '<?xml version="1.0"?>
<bk:book xmlns:bk=''urn:loc.gov:books''
xmlns:isbn=''urn:ISBN:0-395-36341-6''>
<bk:title>Cheaper by the Dozen</bk:title>
<isbn:number>1568491379</isbn:number>
</bk:book>';
xmlt := XMLType( xml );
root := xmlt.getRootElement();
dbms_output.put_line( 'StringVal: ' || xmlt.getStringVal() ); -- The XML is ok
dbms_output.put_line( 'Namespace: ' || xmlt.getNameSpace() ); -- Returns NULL
dbms_output.put_line( 'Root element: ' || root ); -- Returns book
dbms_output.put_line( 'Exists: ' || xmlt.existsNode('book') ); -- Returns ZERO
xmlt1 := xmlt.extract( 'bk:book' ); Raises error (see above)
xmlt1 := xmlt.extract( 'bk::book' ); Raises error (see above)
xmlt1 := xmlt.extract( 'book', 'bk' ); Raises error (see above)
--xmlt1 := xmlt.extract( 'book' );
dbms_output.put_line( 'StringVal: ' || xmlt1.getStringVal() ); Raises error
END;
/