0

the xml looks like this:

<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
   <soap12:Body>
     <BlockUpload xmlns="http://mftsolutions.com/">
       <data><Block xmlns="http://mftsolutions.com/BlockUploader/Block"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://mftsolutions.com/BlockUploader/Block BlockSchema.xsd">
     <Header>
         <Identifier>ID10567</Identifier>
     </Header>
 </Block></data>
     </BlockUpload>
   </soap12:Body>
 </soap12:Envelope>

I want to get the value of element Identifier (ID10567).

I've tried some queries like this, but with no result. Probably I'm missing something in xmlNamespaces declarations:

select h_id
from test_xml, 
  xmltable(xmlNamespaces ( default 'http://mftsolutions.com/BlockUploader/Block' 
                          ,'http://mftsolutions.com/' as "mft"
                          ,'http://www.w3.org/2001/XMLSchema-instance' as "xsi"
                          ,'http://www.w3.org/2001/XMLSchema' as "xsd"
                          ,'http://www.w3.org/2003/05/soap-envelope' as "soap12"),
            '//soap12:Envelope/soap12:Body/BlockUpload/data/Block/Header'
                   PASSING XMLTYPE(xml)
                   COLUMNS
                     h_id VARCHAR2(1000) PATH 'Identifier')

What I have missed?

sample table for this query:

create table test_xml (xml clob);

insert into test_xml values ('<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
   <soap12:Body>
     <BlockUpload xmlns="http://mftsolutions.com/">
       <data><Block xmlns="http://mftsolutions.com/BlockUploader/Block"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://mftsolutions.com/BlockUploader/Block BlockSchema.xsd">
     <Header>
         <Identifier>ID10567</Identifier>
     </Header>
 </Block></data>
     </BlockUpload>
   </soap12:Body>
 </soap12:Envelope>');
4

1 回答 1

0

The <BlockUpload> node in XML document belongs to namespace "http://mftsolutions.com/". Reference to this namespace missed in Xpath expression.

Also, <data> node in document implicitly belongs to same namespace, so proper XPath for query must look like:

'//soap12:Envelope/soap12:Body/mft:BlockUpload/mft:data/Block/Header'
于 2014-06-24T12:21:36.190 回答