I've been working on Oracle 11g since a couple months, so don't have enough experience, thank you for helping me out of this. I'm trying to read a big XML file and get just 2 values of this, the thing is that the document I read is kind big. So let me explain you what I'm doing:
Creating a table for storing the xml:
CREATE TABLE xml_table OF XMLType;
Then I read the document for getting it into the table:
PROCEDURE prc_insertXmlFile( dir VARCHAR2, file VARCHAR2) IS
BEGIN
INSERT INTO xml_table
VALUES (XMLType(bfilename(dir, file),
nls_charset_id('AL32UTF8')));
COMMIT;
END;
Now, this is an extract of the document(the insert was ok) :
<?xml version="1.0" encoding="UTF-8"?>
<Report xsi:schemaLocation="VehicleTripSummary http://lol/someServer?%2lol4%2FVehicleTripSummary&rs%3ACommand=Render&rs%3AFormat=XML&rs%3ASessionID=prfwnw554uqweiz0c45eviftfu5&rc%3ASchema=True" Name="VehicleTripSummary" txtReportTitle="Vista Viaje por Vehículo (Resumen)" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="VehicleTripSummary">
<table1 textbox8="Publicado por:" User_Description="Operaciones qwwwq" textbox5="Grupo de Vehículo:" VehicleGroup_Description="Grupo de Vehiculos-qweqe qweqe." textbox16="Período:" LocalTimestampRange="2015-02-03 00:00 .. 2015-02-03 23:59"/>
<tblTripDetails Distance_Abbreviation="Distance(Km)" textbox17="Duración" textbox25="Ultima Conocida Odómetro" Textbox27="Ultima Conocida Hs. Motor" textbox47="Descripción de Vehículo" textbox1="Registro" textbox2="Núm. de Viajes" textbox3="Total" textbox11="Promedio" textbox19="Total" textbox14="Promedio" textbox18="Núm. de Choferes" textbox20="Fecha" textbox24="Lectura" Textbox28="Fecha" Textbox21="Lectura" textbox42="Totales:" textbox44="1987" textbox45="7040" textbox48="287:11:06">
<Detail_Collection>
<Detail Vehicle_Description_1="A144 CL149627" Vehicle_Registration="CL149627" NoOfTrips="0" TotalDistance="0" AverageDistance="0" TotalDuration_Description="00:00:00" AverageDuration_Description="00:00:00" NoOfDrivers="0" LastKnownOdometer="2015-01-30 10:02:58" LastKnownOdometerLocalTimestamp="46" Textbox29="--" Textbox31="--"/>
<Detail Vehicle_Description_1="A38 CL124335 " Vehicle_Registration="CL124335" NoOfTrips="3" TotalDistance="0" AverageDistance="0" TotalDuration_Description="00:08:03" AverageDuration_Description="00:02:41" NoOfDrivers="0" LastKnownOdometer="2015-02-04 16:13:35" LastKnownOdometerLocalTimestamp="283252" Textbox29="--" Textbox31="--"/>
.
.
.
</Detail_Collection>
</tblTripDetails>
</Report>
NOW, what I want is read this to get the value Datail/Vehicle_Registration and Datail/TotalDistance. I´m doing this:
SELECT extractValue(OBJECT_VALUE,'/Report/tblTripDetail/Detail_Collection/Detail[1]//Vehicle_Registration') Detalles
FROM xml_table;
But I couldn't get what the data I wanted.
Thanks in advance.
CHECK THIS OUT: XMLTYPE OPERATIONS
I got this solution, hope it will be helpful for somebody! x) The problem is with the xml name space, we have to remove it by doing this: THE SOLUTION
Then I accessed to the data I need with this code:
PROCEDURE PRC_PRINCIPAL IS
y xmltype;
x XMLType := XMLType(bfilename('PRUEBASTALLERXML', 'VehicleTripSummary.xml'),
nls_charset_id('AL32UTF8'));
BEGIN
SELECT XMLTRANSFORM(x, x.stylesheet)
INTO Y
FROM XMLSTYLESHEETS x
WHERE x.CODE = 'REMNAM';
FOR r IN (
SELECT ExtractValue(Value(p),'/Detail/@Vehicle_Registration') as name
FROM TABLE(XMLSequence(Extract(y,'/Report/tblTripDetails/Detail_Collection//Detail'))) p
) LOOP
htp.p(r.name);
END LOOP;