Unable to get XML attributes in elements with function XMLTABLE

I cannot get attributes of an XML stored in an XMLTYPE column.  The XML uses primarily attributes rather than items with a value of tag/matching.  If I put the knot in the first argument of the function XMLTABLE, he shoots the attribute at this level.  However, when I try to retrieve the attributes of the child node, I don't get the attribute values.  I'm working on the 11.2.0.3.0 Oracle database version.

This is the create/insert statements:

CREATE TABLE XML_TBL_TEST

(

ID NUMBER,

XMLTYPE data

);

INSERT INTO XML_TBL_TEST

VALUES (1, xmltype ("< user >

< username = "Name1" >

<>projects

< Project = '100' QId OpId = PName "101" = "PName1" >

< group >

< group GName = "GName1" >

elements <>

< point OName = "OName1" Type = "Type1" >

< ops >

< op PType = material 'PType1' = 'Mat1"series = PStyle"Series1"="PStyle1">

< options >

< name of option = "Name1" Value = "V1" / >

< name of option = "Name2" Value = "V2" / >

< name of option = "Name3" Value = "V3" / >

< / options >

< /op >

< op PType = material 'PType2' = 'Mat2"series = PStyle"Series2"="PStyle2">

< options >

< option Name = "Conjoint4" Value = "V4" / >

< name of option = "Name5" Value = "V5" / >

< option Name = "Name6" Value = "V6" / >

< / options >

< /op >

< / ops >

< / point >

< point OName = "OName2" Type = "Type2" >

< / point >

< / object >

< / Group >

< group GName = "GName2" >

< point OName = "OName3" Type = "Type3" >

< / point >

< / Group >

< / group >

< / project >

< OpId project = "200" QId = "201" PName = "PName2" >

< / project >

< / project >

< / user >

< username = "Name2" >

< / user >

< username = "Name3" >

< / user >

((< / user > '));

The query below will draw the Name attribute in the element of the user but not the OpId, QId and PName attributes on the child of the Project element.

SELECT x.*

OF XML_TBL_TEST t.

XMLTABLE (-with xmlnamespaces ('http://www.w3.org/2001/XMLSchema-instance' as "xsi"), )

"/ Users/user.

PASSAGE t.data

COLUMNS - ID FOR ORDINALITE 'ID,' NUMBER

Name VARCHAR2 (30) PATH "@Name."

PATH of VARCHAR2 (30) PName ' / Projects/Project/@PName',

QId NUMBER PATH ' / Users/User/Projects/Project/@QId' by DEFAULT 0,

OpId NUMBER PATH '. (/ Project/@OpId' 0 by DEFAULT) x;

The following query will get OpId, QId and PName attributes in the child project item.

SELECT x.*

OF XML_TBL_TEST t.

XMLTABLE (-with xmlnamespaces ('http://www.w3.org/2001/XMLSchema-instance' as "xsi"), )

"/ Users/user/projects/Project.

PASSAGE t.data

COLUMNS - UserName VARCHAR2 (30) PATH "@Name."

PName VARCHAR2 (30) PATH "@PName."

QId NUMBER PATH "@QId" default 0,

OpId NUMBER PATH "@OpId" DEFAULT 0) x;

How can I get all the attributes for a given element in the XML document.  I tried a number of options without success.

FYI, SM

Because there may be several projects under a user, you must use a 2nd XMLTABLE chained (or a more complex XQuery expression) to retrieve the attributes of two orders:

SQL > SELECT / * + no_merge (x 1) * /.

2 x 1. Username, x2.*

Xml_tbl_test 3 t

4, XMLTABLE)

5 "/ users/user.

6 in PASSING t.data

7 COLUMNS

Username 8 VARCHAR2 (30) PATH '@Name '.

9, XMLType PATH "Projects/Project" projects

(10) x 1

11, XMLTABLE)

12 "/ project".

13 by the WAY x 1. Projects

14 COLUMNS

NUMBER 15 QId PATH '@QId '.

16, ROAD NUMBER OpId '@OpId '.

17, PName VARCHAR2 (30) PATH '@PName '.

(18) (+) x 2

19;

QID OPID PNAME USERNAME

------------------------------ ---------- ---------- ------------------------------

Name1 PName1 101 100

Name1 PName2 201 200

NAME2

NAME3

NB: I used the trick no_merge because of a bug in my version (11.2.0.4)

Tags: Database

Similar Questions

  • I have a samsung galaxy s2 sprint phone and I just did an update for my phone. After doing so, I am unable to get my phone to register with my computer to get my music files off of it?

    I have a samsung galaxy s2 sprint phone and I just did an update for my phone. After doing so, I am unable to get my phone to register with my computer to get my music files off of it? How can I fix this problem? It worked absolutely fine before the update.

    Contact your cellular provider or Samsung with this problem.

  • ' Gets an attribute xsi: type with XMLType object relational storage.

    Hello


    How to recover the attribute xsi: type, when you use storage relational XMLType object.

    When you have for example a ProductOrder object type and one object type MoveOrder what a CustomerOrder extensions type how to recover if the CustomerOrder is a kind of MoveOrder or ProductOrder attribute:

    < ns2:customerOrder xsi: type = "ns3:UpcProductOrder" >


    I would use the XMLTable service in combination with the XPath rewrite.

    version of the database 11.2.0.2

    Thanks for the details.

    As I said in my first answer, the prefix xsi is predefined, don't try to redeclare him.

    I know that sounds strange and is in contradiction with what the manual, but it seems to work that way with the storage of GOLD.

    http://docs.Oracle.com/CD/E11882_01/AppDev.112/e23094/xdb_xquery.htm#CBAJBDFA

    You can use these prefixes in XQuery expressions without first declaring in the prologue of the XQuery expression. You can redefine any of them except xml in the prologue.

    If documentation bug or implementation bug? I do not know.

    In any case:

    SQL> BEGIN
      2    DBMS_XMLSCHEMA.registerSchema(
      3      SCHEMAURL => 'test_otn.xsd',
      4      SCHEMADOC => bfilename('TEST_DIR','test_otn.xsd'),
      5      CSID => nls_charset_id('AL32UTF8')
      6    );
      7  END;
      8  /
    
    PL/SQL procedure successfully completed
    
    SQL>
    SQL> insert into cust_order values (xmltype
      2  ('
      3  
      6  a
      7  b
      8  '));
    
    1 row inserted
    
    SQL>
    SQL> SELECT order_id
      2       , order_item
      3       , order_type
      4  FROM cust_order
      5     , XMLTABLE (
      6         XMLNamespaces ('http://bla.com' as "ns1")
      7       , '/ns1:customerOrder'
      8         passing object_value
      9         columns order_id   varchar2(20) path 'ns1:orderId'
     10               , order_item varchar2(20) path 'ns1:orderItem'
     11               , order_type varchar2(30) path '@xsi:type'
     12       ) ;
    
    ORDER_ID             ORDER_ITEM           ORDER_TYPE
    -------------------- -------------------- ------------------------------
    a                    b                    http://bla.com:ProductOrder
     
    

    And if you do want the local name:

    SQL> SELECT order_id
      2       , order_item
      3       , order_type
      4  FROM cust_order
      5     , XMLTABLE (
      6         XMLNamespaces ('http://bla.com' as "ns1")
      7       , '/ns1:customerOrder'
      8         passing object_value
      9         columns order_id   varchar2(20) path 'ns1:orderId'
     10               , order_item varchar2(20) path 'ns1:orderItem'
     11               , order_type varchar2(30) path 'local-name-from-QName(@xsi:type)'
     12       ) ;
    
    ORDER_ID             ORDER_ITEM           ORDER_TYPE
    -------------------- -------------------- ------------------------------
    a                    b                    ProductOrder
     
    

    Hope that helps.

  • When you connect to the Web site, get "XML error: no element found"

    I can log on the website using IE 6 with success. I installed User Agent Switcher then chose Internet Explorer 6, but without success. I welcomed all cookies and disabled the blocker Popup, but still no luck.

    It is possible that the site only works in IE and not in Firefox. Change the user agent will not help in this case.

    In this case, you can use an extension like IE Tab or IE to use the IE rendering engine in Firefox.

  • Unable to get my computer set up with my printer

    Original title: I tried to install my new printer to my computer.  Using the installation wizard supplied with the printer, when I try to enter the text requested that the typed letters and words are not visible.

    I tried to install my new printer to my computer.  Using the installation wizard supplied with the printer, when I try to enter the text requested that the typed letters and words are not visible.  So he always tells me that my information is not valid and does not accept anything.  Why this is happening and what can I do about it?  Any help on this would be greatly appreciated. Thank you, GLC! **

    Hello

    • What is the brand and model of the printer?
    • Are what Installation Wizard you referring?
    • You have installed all the drivers on the site of the printer manufacturer?
    • Where exactly you are trying to enter into the text?

    Response with more information.

    See also:

    Find and install printer drivers

    http://Windows.Microsoft.com/en-us/Windows-Vista/find-and-install-printer-drivers

  • need help to get the value using the REGEXP_REPLACE function.

    I am trying to extract the value placed between "< listitems >... < / listitems >" but I am unable to get these value using the REGEXP_REPLACE function.
    select REGEXP_REPLACE('<InputParameters></ParamSet><listitems>14545454</listitems></ParamSet></InputParameters>'
    ,'(<InputParameters>.*<listitems>)(.*)(</listitems>.*<InputParameters>)'
    ,'\2') from dual;
    required output:
     1454554
    Can someone please help me achieve this goal.

    Hello

    You forgot the / before the last InputParameters. If fix you that, your code will work.

    Here is a slightly different way:

    SELECT  REGEXP_REPLACE ( '14545454'
                     , '^.*?(.*?).*$'
                     , '\1'
                     )     AS listitems
    FROM    dual
    ;
    

    Least to type, the less likely you will have to make typos.
    If there are 2 (or more) elements of listitmes, 1 will be returned.

    From Oracle 11.1, you can also use REGEXP_SUBSTR. I have Oracle 10.2 avaialable now, so I can test the following, but I think you'd say:

    SELECT  REGEXP_SUBSTR ( '14545454'
                     , '(.*?)'
                     , 1
                     , 1
                     , NULL
                     , 1
                     )     AS listitems
    FROM    dual;
    

    When it comes with the text that is or looks to, XML, consider using XML functions.

  • Unable to get the elements placed at the top and bottom of the cell of the table with vertical-align

    Hello

    I have a three-day educational courses in the list table. In each cell, I have the title of the presentation at the top with the name of the speaker below. Because some titles are longer than others, the line grows (rightly) as longer securities are covered in Word. So far so good. Now, I want all the titles to always start at the same distance from the surface of the cell (I use padding 2px) and names of speaker all be equidistant from the lower border, (i.e. 2px).

    I tried to place the title elements with < span style = "vertical-align: top" > </span > presentation title

    and the name of the speaker as < span style = "vertical-align: bottom" > name </span > Speaker

    and I tried the same method with < div > and < p > tags. Items don't move. Can someone tell me how to make the names of the speakers will be all aligned at the bottom of each cell?

    Here is an example of the code table I've tried:

    (Thanks!)

    < table style = "text-align: center;" do-family: Arial; background-color: #f7d49c; "border ="2"bordercolor =" #467E9F "cellpadding ="2 ".

    "cellspacing ="0"width ="900">"

    < tbody >

    < b >

    < td width = "300" > < span style = "" vertical-align: top; "> This is a short title </span > < br / >"

    < span style = "vertical-align: bottom" > name </span > < table > Speaker

    < td width = "300" > < div > is the title of another presentation, which is really long because some of the presentations have titles like that < / div > < br / >

    < div style = "vertical-align: bottom" > Speaker name < / div > < table >

    < td width = "300" > < span style = "vertical-align: top" > This is yet another presentation with a semi-long title </span > < br / >

    < span style = "vertical-align: bottom" > < table > </span > Speaker's name

    < /tr >

    < b >

    < td > < table >

    < td > < table >

    < td > < table >

    < /tr >

    < b >

    < td > < table >

    < td > < table >

    < td > < table >

    < /tr >

    < b >

    < td > < table >

    < td > < table >

    < td > < table >

    < /tr >

    < / tbody >

    < /table >

    By default, the content of the table cell is average aligned.  You need not do anything.

    If you want your cell vertically aligned up or down, you can specify it in your CSS.  These effects all the text inside the cell.   It's all or nothing.

    Some text that is aligned at the top Some bottom-aligned text

  • Parsing XML and get the attributes of a tag

    Hello

    When parsing XML for application of Cascades in C++, I am able to get the value of a tag as follows:

    00000

    But I also want to get the attributes of a tag:

    But I don't know how to get the 'CA' and 'California' attributes with my current code.  Can anyone help?  Here is the code I use to parse the XML code:

    void CMController::requestFinished(QNetworkReply* reply) {
    
        if (reply->error() == QNetworkReply::NoError) {
    
            QXmlStreamReader xml;
    
            QByteArray data = reply->readAll();
            xml.addData(data);
    
            QString zip;
            QString id;
            QString location;
    
            while (!xml.atEnd() && !xml.hasError()) {
    
                /* Read next element.*/
                QXmlStreamReader::TokenType token = xml.readNext();
    
                /* If token is just StartDocument, we'll go to next.*/
                if (token == QXmlStreamReader::StartDocument) {
                    continue;
                }
    
                /* If token is StartElement, we'll see if we can read it.*/
                if (token == QXmlStreamReader::StartElement) {
    
                    if (xml.name() == "zip") {
                        zip = xml.readElementText();
                    }
    
                    if (xml.name() == "id") {
                        ???
                    }
    
                    if (xml.name() == "location") {
                        ???
                    }
    
                }
    
            }
    
            emit succeeded(result);
    
        } else {
            emit failed();
        }
    
        reply->deleteLater();
    
    }
    

    Thank you!

    I found a working example:

    if(xml.name() == "state"){
        QXmlStreamAttributes attrib = xml.attributes();
        QStringRef ref = attrib.value("location");
        qDebug() << "location: " << ref;
    }
    
  • xmlObject - value of the element with a particular attribute

    Hello

    In an xmlObject, I try to set the value of the element xml with a special attribute, but it does not work

    //get value of element with a particular attribute
    var myValue = xmlObject.ELEMENTS.ELEMENT.(@category == "myCategory"))// works fine
    //set value of element with a particular attribute
    var myValue = "foo"
    xmlObject.ELEMENTS.ELEMENT.(@category == "myCategory"))= myValue // doesn't work
    

    Thanks for your help

    Concerning

    The E4X (?) XML syntax is powerful, but you can easily get lost with the bad node types. That is why my answer included the .writeln $ nature - 'list' - and used an index for the change; After validation, I found that your assignment would have also worked on the only indexed element. Thanks for sharing your discovery with setChildren() - who apparently works also on the lists.

    Dirk

  • Enforcement of XML attribute with a structure?

    I use xmlParse() to read an XML file into a structure and then deal with the structure (replace some of the XML attributes) and then write structure back as an XML file. The problem is that I lost the original order of the XML attributes when I convert a structure and instead end up with a new attribute for each element that is alphabetical order.

    In other: c = 'text' d = 'text' element has = "text" / >

    be rewritten in the form: element = 'text' c = 'text' d = "text" / >

    which is a problem for this application.

    Is it possible to work with XML in CF but keep ordering attribute (LinkedHashMap instead of a structure, perhaps)?

    Thank you.

    Walter

    If you need to control the order of the attributes, you must write your xml code on hand, according to the XML specification, ordering attribute must not be important, so strictly speaking your condition here requires something XML which is contrary to his intention.  And, therefore, has no way of making CF respect something that inherently isn't supposed to be respected.

    NB: "I use xmlParse() to read an XML file in a structure"... xmlParse() creates an XML object, not a struct, so what you ask in your last paragraph doesn't really sense.  xmlParse() will only create an XML object. If you want to read the XML data as something else than XML, you need to write your own function.

    The best solution here, if poss, is to remove the importance of the order attribute in your application, because it is "wrong" to deduct any order, and you do a little logic a rod for your own back based on this ranking.

    Not an answer 'just do it like this', I'm sorry, but that's what you get when the question is immersed in a Pandora's box... ;-)

    --
    Adam

  • Try to get an XML attribute from an XMLType variable

    Hi people,

    I'm parsing a XML very well, except for a couple of attributes in the first element. I do not know how to reference their (start date / to date). Here is an example XML and the way I am referencing the data.

    <? XML version = "1.0" encoding = "UTF-8"? >
    < date of animal - data = "2013-01-07" to date "07-01-2013" = >
    < animal >
    < name > dog < / name >
    < color > Brown < / color >
    < / animal >
    < animal >
    < name > cat < / name >
    < color > Black < / color >
    < / animal >
    < / animal - data >

    I have no problem get the data as well, assuming the above XML code is in a variable named v_XML of type XMLType

    v_AnimalCount: = 1;

    All in v_XML.existsNode ('/ data/animal-animal ['| v_AnimalCount |']) ') = 1
    loop
    v_Name: = v_XML.extract ('/ data/animal-animal ['| v_AnimalCount |'] /Name/Text()').getStringVal ();)
    v_color: = v_XML.extract ('/ data/animal-animal ['| v_AnimalCount |'] /Color/Text()').getStringVal ();)
    v_animalCount: = v_animalCount + 1;
    end loop;

    But how do I get the attributes of this day and this day using the same type of syntax (v_XML.extract)?

    Thank you very much!

    -Adam

    Adam vonNieda says:
    But how do I get the attributes of this day and this day using the same type of syntax (v_XML.extract)?

    In the XPath language, an attribute is accessible via the "attribute:" axis, or its most commonly used abbreviation '@':

    v_from_date        := v_XML.extract('/animal-data/@from-date').getStringVal();
    

    What is your version of db?
    What about using XMLTable instead of PL/SQL?

  • Can someone please tell me the "see correct / more effective to get the 'status' XML ' attributes

    Can someone please tell me the "see correct / more effective to get the 'status' XML ' attributes (ID, CssClass, Description and IsActive to the XML code below):

    Implementation will be the standalone .swf file

    (XML)

    <ArrayOfLineStatus>
    <LineStatus ID="0" StatusDetails="">
        <BranchDisruptions/><Line ID="1" Name="Bakerloo"/>
        <Status ID="GS" CssClass="GoodService" Description="Good Service" IsActive="true">         
             <StatusType ID="1" Description="Line"/></Status></LineStatus>
    </ArrayOfLineStatus>

    < ArrayOfLineStatus >

    < LineStatus ID = "0" StatusDetails = "" >

    < BranchDisruptions / >

    < line ID = "1" Name = "Bakerloo" / >

    < State ID = 'GS' CssClass = "GoodService" Description = "Good Service" IsActive = "true" >

    < StatusType ID = '1' Description = 'Line' / > < / status >

    < / LineStatus >

    < / ArrayOfLineStatus >

    There is no good way with as2:

    trace(this.firstChild.childNodes[1].childNodes[4].) Attributes ['ID']);

    trace(this.firstChild.childNodes[1].childNodes[4].) Attributes ['CssClass']);

    etc.

  • XML attribute 'with' reserved?

    While working on an implementation of XMPP I notice the "with" continuous attribute to throw errors when trying to access to set or get the data from it. What is a reserved word or something? So in fact difficult given "with" is widely used in the specifications...

    var XML = < rootNode >

    < = 'test' without the 'rest' = > cool < / item >

    < / rootNode >;

    trace (XML. Item.@without); No problem

    trace (XML. Item.@with); Uncomment and you will get the error "syntax error: expected identifier with.»

    It may be how access you during the review of the reserved words. Try trace (xml.item.attribute ('with')); or trace(xml.item.@["with"]);

  • How can I get the value of the element with the namespace?

    I tried to get an element of value in xml a namespace, but I can't.
    I removed the namespace, I get a value of the element.

    How can I get a value of the element with the namespace?

    -1. Error ----------- xml ------------------------------
    <? XML version = "1.0" encoding = "UTF-8"? >

    * < TaxInvoice xmlns = "" urn: kr: or: kec:standard:Tax:ReusableAggregateBusinessInformation:1:0 "xmlns: xsi ="http://www.w3.org/2001/XMLSchema-instance"xsi: schemaLocation =" urn: kr: or: kec:standard:Tax:ReusableAggregateBusinessInformation:1:0 http://www.kec.or.kr/standard/Tax/TaxInvoiceSchemaModule_1.0.xsd "> *"
    < ExchangedDocument >
    < IssueDateTime > 20110810133213 < / IssueDateTime >
    < ReferencedDocument >
    < ID > 318701 - 0002 / < ID >
    < / ReferencedDocument >
    < / ExchangedDocument >
    < TaxInvoiceDocument >
    < IssueID > 201106294100 < / IssueID >
    < > 0101 TypeCode < / TypeCode >
    < IssueDateTime > 20110810 < / IssueDateTime >
    < PurposeCode > 02 < / PurposeCode >
    < / TaxInvoiceDocument >
    < TaxInvoiceTradeLineItem >
    < SequenceNumeric > 1 < / SequenceNumeric >
    < > 200000000 InvoiceAmount < / InvoiceAmount >
    < TotalTax >
    < CalculatedAmount > 20000000 < / CalculatedAmount >
    < / TotalTax >
    < / TaxInvoiceTradeLineItem >
    < / TaxInvoice >


    -2. success - xml - remove namespace.
    <? XML version = "1.0" encoding = "UTF-8"? >
    < TaxInvoice >
    < ExchangedDocument >
    < IssueDateTime > 20110810133213 < / IssueDateTime >
    < ReferencedDocument >
    < ID > 318701 - 0002 / < ID >
    < / ReferencedDocument >
    < / ExchangedDocument >
    < TaxInvoiceDocument >
    < IssueID > 201106294100 < / IssueID >
    < > 0101 TypeCode < / TypeCode >
    < IssueDateTime > 20110810 < / IssueDateTime >
    < PurposeCode > 02 < / PurposeCode >
    < / TaxInvoiceDocument >
    < TaxInvoiceTradeLineItem >
    < SequenceNumeric > 1 < / SequenceNumeric >
    < > 200000000 InvoiceAmount < / InvoiceAmount >
    < TotalTax >
    < CalculatedAmount > 20000000 < / CalculatedAmount >
    < / TotalTax >
    < / TaxInvoiceTradeLineItem >
    < / TaxInvoice >




    -program-
    procedure insert_table
    (
    l_clob clob,
    OK, Boolean.
    Error out varchar2
    )
    is
    l_parser dbms_xmlparser. Analyzer;
    xmlDoc xmldom.domdocument;

    l_doc dbms_xmldom. DOMDocument;
    l_nl dbms_xmldom. DOMNodeList;
    l_n dbms_xmldom. DOMNode;
    l_root DBMS_XMLDOM.domelement;
    l_node DBMS_XMLDOM.domnode;
    l_node2 DBMS_XMLDOM.domnode;
    l_text DBMS_XMLDOM. DOMTEXT;

    buf VARCHAR2 (30000);

    XMLParseError exception;

    TYPE tab_type is Table of xml_upload % ROWTYPE;
    t_tab tab_type: = tab_type();
    pragma exception_init (xmlparseerror,-20100);
    l_node_name varchar2 (300);

    Start
    l_parser: = dbms_xmlparser.newParser;
    l_doc: = DBMS_XMLDOM.newdomdocument;
    dbms_xmlparser.parseClob (l_parser, l_clob);
    l_doc: = dbms_xmlparser.getDocument (l_parser);
    l_n: = dbms_xmldom.makeNode (l_doc);

    l_nl: = dbms_xslprocessor.selectNodes (l_n, ' / TaxInvoice/TaxInvoiceDocument ');

    FOR cur_tax in 0.dbms_xmldom.getLength (l_nl) - 1 LOOP
    l_n: = dbms_xmldom.item (l_nl, cur_tax);

    t_tab.extend;

    t_tab (t_tab.last) .ed_id: = '5000000';

    dbms_xslprocessor.valueOf (l_n, ' IssueID / text () ', t_tab (t_tab.last) .tid_issue_id);
    dbms_xslprocessor.valueOf (l_n, ' TypeCode / text () ', t_tab (t_tab.last) .tid_type_code);

    END LOOP;

    FORALL i IN t_tab.first... t_tab. Last
    INSERT INTO xml_upload VALUES t_tab (i);

    COMMIT;

    dbms_xmldom.freeDocument (l_doc);
    correct: = true;

    exception
    When xmlparseerror then
    -xmlparser.freeparser (l_parser);
    correct: = false;
    error: = sqlerrm;

    end insert_table;
    l_nl := dbms_xslprocessor.selectNodes(l_n, '/TaxInvoice/TaxInvoiceDocument');
    

    try to change as follows

    l_nl := dbms_xslprocessor.selectnodes(l_n,'/TaxInvoice/TaxInvoiceDocument','xmlns="urn:kr:or:kec:standard:Tax:ReusableAggregateBusinessInformation:1:0"');
    

    Published by: Alexandr on August 17, 2011 12:36 AM

  • Retrieves the value of the XML attribute for multiple element sequence

    Guys,

    I have already posted this in the forum XML DB, but some of you could help me.


    I have searched for a solution for this and couldn't quite. I'm trying to get multiple entries in a node attribute values. It workes for a single node, but for many nodes, it fails. Could you please give me a solution?

    SQL> select extractvalue(column_value, '/WORLD/COUNTRY/@NAME') COUNTRY_NAME
      2        ,extractvalue(column_value, '/WORLD/COUNTRY/CITY/@NAME') CITY_NAME
      3        ,extractvalue(column_value, '/WORLD/COUNTRY/CITY/@POPULATION') POPULATION
      4  from xmltable('WORLD' passing xmltype('
      5  <WORLD>
      6  <COUNTRY NAME="INDIA">
      7  <CITY NAME="MUMBAI" POPULATION="10000"></CITY>
      8  </COUNTRY>
      9  </WORLD>'
     10  ));
     
    COUNTRY_NAME CITY_NAME POPULATION
    ---------------------- ------------------ -------------------
    INDIA MUMBAI 10000
    When I execute the same for several nodes, it fails, please guide me. Please also let me know how to handle if I have an XML file that contains this data.

    SQL> select extractvalue(column_value, '/WORLD/COUNTRY/@NAME') COUNTRY_NAME
      2        ,extractvalue(column_value, '/WORLD/COUNTRY/CITY/@NAME') CITY_NAME
      3        ,extractvalue(column_value, '/WORLD/COUNTRY/CITY/@POPULATION') POPULATION
      4  from xmltable('WORLD' passing xmltype('
      5  <WORLD>
      6  <COUNTRY NAME="INDIA">
      7  <CITY NAME="MUMBAI" POPULATION="10000"></CITY>
      8  <CITY NAME="CHENNAI" POPULATION="2000"></CITY>
      9  <CITY NAME="BANGALORE" POPULATION="13000"></CITY>
     10  <CITY NAME="HYDERABAD" POPULATION="14000"></CITY>
     11  </COUNTRY>
     12  </WORLD>'
     13  ));
    select extractvalue(column_value, '/WORLD/COUNTRY/@NAME') COUNTRY_NAME
                                                                      *
    ERROR at line 1:
    ORA-19025: EXTRACTVALUE returns value of only one node
    See you soon
    Sarma.

    So, this is the first step:

    SQL> with test as
      2  (select xmltype('
      3                 
      4                 
      5                 
      6                 
      7                 
      8                 
      9  ') resp from dual)
     10  select country
     11       , cities
     12  from xmltable('WORLD/COUNTRY' passing (select resp from test)
     13                         columns country varchar2(50) path '/COUNTRY/@NAME'
     14                               , cities xmltype path '/COUNTRY/CITY') world
     15  /
    
    COUNTRY         CITIES
    --------------- --------------------------------------------------
    INDIA           
    

    two columns, a varchar2 and an xmltype.

    Then do the same with the second column, pass the XML to the function XMLTABLE

    SQL> with test as
      2  (select xmltype('
      3                 
      4                 
      5                 
      6                 
      7                 
      8                 
      9  ') resp from dual)
     10  select country
     11       , cit.name
     12       , cit.population
     13  from xmltable('WORLD/COUNTRY' passing (select resp from test)
     14                         columns country varchar2(50) path '/COUNTRY/@NAME'
     15                               , cities xmltype path '/COUNTRY/CITY') world
     16     , xmltable ('CITY' passing cities
     17                columns name varchar2(50) path '@NAME'
     18                      , population number path '@POPULATION'
     19                ) cit
     20  ;
    
    COUNTRY         NAME                                               POPULATION
    --------------- -------------------------------------------------- ----------
    INDIA           MUMBAI                                                  10000
    INDIA           CHENNAI                                                  2000
    INDIA           BANGALORE                                               13000
    INDIA           HYDERABAD                                               14000
    

Maybe you are looking for