sql - Issue With Pulling Remote XML Data into Oracle Database -
in oracle database, reading xml restful web service looks this:
<ns1:parent xmlns:ns1="http://www.example.com/xml" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xs1:schemalocation= "http://www.example.com/xml http://www.w3.org/2001/xmlschema-instance"> <ns1:child> <ns1:options></ns1:options> <ns1:variables></ns1:variables> <ns1:values> <ns1:value qualifiers="x" date="sometime">value1</ns1:value> <ns1:value qualifiers="x" date="someothertime">value2</ns1:value> ... <ns1:value qualifiers="x" date="some100thtime">value100</ns1:value> </ns1:values> </ns1:child>
i trying take data , extract database using code below. however, when creates 1 record sysdate field , other 2 values blank. attempted xmltable, had same result. i'm thinking there's issue namespace, can't find proper syntax , other combinations i've tried don't return rows @ all.
we pull data another, identical data source not use namespaces, , code works fine (without of namespaces, of course). getting syntax of namespaces wrong somewhere?
declare myxmltype xmltype := xmltype(we use function pull in xml file here); begin /*outputting xmltype here shows data in it*/ insert output_table select extractvalue(value(p), '/values/ns1:value', 'xmlns:ns1="http://www.example.com/xml"') myvalue, extractvalue(value(p), '//values/ns1:value/@ns1:date', 'xmlns:ns1="http://www.example.com/xml"') mytime, sysdate read_date table(xmlsequence(extract(myxmltype, '/ns1:parent/ns1:child/ns1:values', 'xmlns:ns1="http://www.example.com/xml"')))p; commit; end;
you can use xmltable thought, need supply xmlnamespaces clause too. using bind variable called string
holds xml text (with couple of corrections):
var string varchar2(200); begin :string := '<ns1:parent xmlns:ns1="http://www.example.com/xml" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" ns1:schemalocation= "http://www.example.com/xml http://www.w3.org/2001/xmlschema-instance"> <ns1:child> <ns1:values> <ns1:value qualifiers="x" date="sometime">value1</ns1:value> <ns1:value qualifiers="x" date="someothertime">value2</ns1:value> </ns1:values> </ns1:child> </ns1:parent>'; end; / select myvalue, mytime, sysdate read_date xmltable(xmlnamespaces('http://www.example.com/xml' "ns1"), '/ns1:parent/ns1:child/ns1:values/ns1:value' passing xmltype(:string) columns myvalue varchar2(20) path '.', mytime varchar2(20) path '@date' ); myvalue mytime read_date -------------------- -------------------- ---------- value1 sometime 2016-07-25 value2 someothertime 2016-07-25
you can same thing insert ... select
using myxmltype
variable in passing
clause, instead of xmltype(:string)
.
extractvalue
deprecated anyway, , can return 1 node ora-19025 if had xpath right.
Comments
Post a Comment