Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XMLSequence EXTRACT HEAD and DETAIL in ORACLE 9.2

1019748Jun 25 2013 — edited Jun 27 2013

Hi, sorry about my english i am from argentine.

I have this XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<arrayOfServicio >

    <Servicio>

        <Nombre>Autenticacion</Nombre>

        <Descripcion>ws</Descripcion>

        <Activo>true</Activo>

        <Version>1.0</Version>

        <MetodosEntity>

            <Metodo>

                <Nombre>RequestTicket</Nombre>

                <Activo>true</Activo>

                <Version>1.0</Version>

            </Metodo>

        </MetodosEntity>

    </Servicio>

    <Servicio>

        <Nombre>Consultas</Nombre>

        <Descripcion>wsConsultas</Descripcion>

        <Activo>true</Activo>

        <Version>1.0</Version>

        <MetodosEntity>

            <Metodo>

                <Nombre>GetVigencia</Nombre>

                <Activo>true</Activo>

                <Version>1.0</Version>

            </Metodo>

            <Metodo>

                <Nombre>GetSiniestralidad</Nombre>

                <Activo>true</Activo>

                <Version>1.0</Version>

            </Metodo>

            <Metodo>

                <Nombre>GetAgrupados</Nombre>

                <Activo>true</Activo>

                <Version>1.0</Version>

            </Metodo>

            <Metodo>

                <Nombre>GetSiniestralidadPorCuil</Nombre>

                <Activo>true</Activo>

                <Version>1.0</Version>

            </Metodo>

        </MetodosEntity>

    </Servicio>

    <Servicio>

        <Nombre>Referencias</Nombre>

        <Descripcion>wsReferencias</Descripcion>

        <Activo>true</Activo>

        <Version>1.0</Version>

        <MetodosEntity>

            <Metodo>

                <Nombre>TablaReferencia</Nombre>

                <Activo>true</Activo>

                <Version>1.0</Version>

            </Metodo>

            <Metodo>

                <Nombre>ListadoReferencia</Nombre>

                <Activo>true</Activo>

                <Version>1.0</Version>

            </Metodo>

        </MetodosEntity>

    </Servicio>

    <Servicio>

        <Nombre>General</Nombre>

        <Descripcion>WsGeneral</Descripcion>

        <Activo>true</Activo>

        <Version>1.0</Version>

        <MetodosEntity>

            <Metodo>

                <Nombre>GetServicios</Nombre>

                <Activo>true</Activo>

                <Version>1.0</Version>

            </Metodo>

        </MetodosEntity>

    </Servicio>

    <Servicio>

        <Nombre>eServicios</Nombre>

        <Descripcion>wseServicios</Descripcion>

        <Activo>true</Activo>

        <Version>1.0</Version>

        <MetodosEntity>

            <Metodo>

                <Nombre>SetComunicacion</Nombre>

                <Activo>true</Activo>

                <Version>1.0</Version>

            </Metodo>

        </MetodosEntity>

    </Servicio>

    <Servicio>

        <Nombre>VentanillaART</Nombre>

        <Descripcion>wsVentanillaART</Descripcion>

        <Activo>true</Activo>

        <Version>1.0</Version>

        <MetodosEntity>

            <Metodo>

                <Nombre>ObtenerNovedades</Nombre>

                <Activo>true</Activo>

                <Version>1.0</Version>

            </Metodo>

        </MetodosEntity>

    </Servicio>

    <Servicio>

        <Nombre>Establecimientos</Nombre>

        <Descripcion>wsEstablecimiento</Descripcion>

        <Activo>true</Activo>

        <Version>1.0</Version>

        <MetodosEntity>

            <Metodo>

                <Nombre>GetConsultaPorCuit</Nombre>

                <Activo>true</Activo>

                <Version>1.0</Version>

            </Metodo>

        </MetodosEntity>

    </Servicio>

</arrayOfServicio>

I am working in ORACLE 9.2 and i wrote this query but the result is not correct, i need to join HEAD and DETAIL in some way but cannot do that...

  select extractvalue(value(head),'//Servicio/Nombre/text()') ,

        extractvalue(value(head),'//Servicio/Descripcion/text()'),

        extractvalue(value(head),'//Servicio/Activo/text()'),

        extractvalue(value(head),'//Servicio/Version/text()')

        ,extractvalue(value(detail),'//Metodo/Nombre/text()')

        ,extractvalue(value(detail),'//Metodo/Activo/text()')

        ,extractvalue(value(detail),'//Metodo/Version/text()')

  from arwt_ws_return x

      , table(xmlsequence(extract (x.x_xmldoc, '/arrayOfServicio/Servicio'))) head

      , table(xmlsequence(extract (x.x_xmldoc, '/arrayOfServicio/Servicio/MetodosEntity/Metodo'))) detail;

Ii really appreciate your help.

Thanks!

This post has been answered by odie_63 on Jun 26 2013
Jump to Answer

Comments

odie_63
Answer

Hi,

You can do that by passing the head element to the second XMLSequence. That way you maintain the correlation between the parent and its children :

select extractvalue(value(head), '/Servicio/Nombre') as srv_nombre

     , extractvalue(value(head), '/Servicio/Descripcion') as srv_desc

     , extractvalue(value(head), '/Servicio/Activo') as srv_activo

     , extractvalue(value(head), '/Servicio/Version') as srv_version

     , extractvalue(value(detail), '/Metodo/Nombre') as met_nombre

     , extractvalue(value(detail), '/Metodo/Activo') as met_activo

     , extractvalue(value(detail), '/Metodo/Version') as met_version

from arwt_ws_return x

   , table(xmlsequence(extract(x.x_xmldoc, '/arrayOfServicio/Servicio'))) head

   , table(xmlsequence(extract(value(head), '/Servicio/MetodosEntity/Metodo'))) detail

;

Please also note that :

- you don't need a descendant axis (//) if you know the exact path

- you don't need to go down to the text() node if you're using extractvalue

Hope that helps.

Marked as Answer by 1019748 · Sep 27 2020
1019748

Thank you so much Odie.

That really helps!

1 - 2
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jul 25 2013
Added on Jun 25 2013
2 comments
1,752 views