XQUERY against an XMLTYPE variable

I have a procedure which gets xmltype instance and i have to use xquery upon that variable.
declare
myxml xmltype;
s varchar2(20);
begin
myxml:=xmltype('<person><name id="1" age="23"/><name id="2" age="25"/></person>');
SELECT
XMLQuery(
'for $i in /person
where $i/age > 24
return $i/id'
PASSING myxml RETURNING CONTENT) into s
FROM DUAL;
end;
BUT i get this error
ORA-06550: line 6, column 1:
PLS-00801: internal error [*** ASSERT at file pdw4.c, line  793; Cannot coerce
between type 43 and type 30; anon_68F441E0__AB[6, 1]]
Please help it is urgent

Not sure if you ever received your answer regarding how to pass an XMLType variable in PLSQL to an XQuery command.
Here is an example of what I've been using... in Oracle 10.2.0.1
SET SERVEROUTPUT ON SIZE 200000
DECLARE
l_result XMLType;
l_xxDoc XMLType := XMLType(
<root>
<things>
<somestuff>12345</somestuff>
<morestuff>12345</morestuff>
</things>
<things>
<somestuff>dfgdfg</somestuff>
<morestuff>werwer</morestuff>
</things>
</root>
PROCEDURE printClobOut
(p_result IN CLOB)
IS
v_xmlstr VARCHAR2(32767);
v_line VARCHAR2(2000);
BEGIN
v_xmlstr := DBMS_LOB.SUBSTR(p_result,32767);
LOOP
EXIT WHEN v_xmlstr IS NULL;
v_line := SUBSTR(v_xmlstr,1,INSTR(v_xmlstr,CHR(10))-1);
DBMS_OUTPUT.PUT_LINE('| '||v_line);
v_xmlstr := SUBSTR(v_xmlstr,INSTR(v_xmlstr,CHR(10))+1);
END LOOP;
END;
BEGIN
select XMLQUERY(
'for $a in $TheDoc/root
return <theresult>
{$a/things}
</theresult>
PASSING l_xxDoc as "TheDoc"
RETURNING CONTENT) into l_result
from dual;
printClobOut(l_result.extract('/').getClobVal());
END;
Kevin

Similar Messages

  • Reorder an xmltype variable in plsql

    I have an xml package sitiing in an xmltype variable.
    Does anyone know a way I can reorder the nodes alphabetically?
    Many Thanks
    Paul

    I can't post the xml.
    The forum just keeps saying content is not allowed.Use &#x7B;code} tags to enclose any code snippets you want to post. It'll preserve formatting and prevent content to be interpreted on the page.
    It's explained here : http://forums.oracle.com/forums/help.jspa
    Does this work for you :
    SQL> set serveroutput on
    SQL>
    SQL> DECLARE
      2 
      3   doc xmltype := xmltype(
      4   '<root>
      5  <things>bbb
      6  <somestuff>1234</somestuff>
      7  <morestuff>5678</morestuff>
      8  </things>
      9  <things>aaa
    10  <somestuff>dog</somestuff>
    11  <morestuff>cat</morestuff>
    12  </things>
    13  </root>'
    14   );
    15 
    16   ordered_doc xmltype;
    17 
    18  BEGIN
    19 
    20   select xmlquery(
    21   'for $i in $d/*
    22    return element {name($i)}
    23    {
    24     for $j in $i/things
    25     order by $j/text()
    26     return $j
    27    }'
    28    passing doc as "d"
    29    returning content
    30   )
    31   into ordered_doc
    32   from dual;
    33 
    34   dbms_output.put_line(ordered_doc.getclobval());
    35 
    36  END;
    37  /
    <root><things>aaa
    <somestuff>dog</somestuff>
      <morestuff>cat</morestuff>
    </things>
    <things>bbb
    <somestuff>1234</somestuff>
      <morestuff>5678</morestuff>
    </things>
    </root>
    PL/SQL procedure successfully completed
    The first "for" in the XQuery is there in case you don't want to hardcode the root element.

  • Is it possible to concatenate XMLType variable

    I'm using XQuery to query relational table and store the result into an xmltype variable as shown below:
    SELECT XMLQuery('<Data>
    {for $c in ora:view("TABLEA")
           let $id := $c/ROW/ID/text(), $code := $c/ROW/CODE/text(),
               return
           <result>
             <type>I</type>
             <id>{$id}</id>
    <code>{$code}</code>
    </result> </Data>' RETURNING CONTENT)
    INTO V_Delete FROM dual;
    Similarly, I query other tables and store the result in xmltype variable. My requirement is to generate one xml file out of it. This would mean that I would need to consolidate the values stored in different xmltype variables. Is it possible to concatenate the xmltype varialbe? If so, how? If not, what is the alternative? I tried converting it to string, but then the 4000 limit caused an error.

    Hi, as I said I have not done that myself. But you can read chapter 4 of the XDB Developer's Guide of the Oraclce docs and I think it may help. The examples there show that those functions are used to update a table. It has this example,
    UPDATE purchaseorder
    SET OBJECT_VALUE =
    appendChildXML(OBJECT_VALUE,
    '/PurchaseOrder/Actions/Action[1]',
    XMLType('<Date>2002-11-04</Date>'))
    WHERE existsNode(OBJECT_VALUE,
    '/PurchaseOrder[Reference="AMCEWEN-20021009123336171PDT"]')
    = 1;
    SELECT extract(OBJECT_VALUE, '/PurchaseOrder/Actions/Action[1]')
    FROM purchaseorder
    WHERE existsNode(OBJECT_VALUE,
    '/PurchaseOrder[Reference="AMCEWEN-20021009123336171PDT"]')
    = 1;
    That was why I thought using a global temp table would help in this kind of operation. What I did was using select xmlelement(namespace declarations) from dual, then using a nested (select xmlelement() ) inside the from dual part. I have to select from many different tables to create one xml and it works for me, but I did not try the other ways. If you just need to attach the prolog and namespace stuff, you can store them in a clob or varchar2 var and convert the xml to clob and that simply concantenate them, and then convert the clob back to xml. In 10g there is also the new XMLProlog (I forgot the exact name at this moment) function. Check that out and see if it will work for you.
    ben

  • Updatexml on xmltype variable

    Is there a way to update the XML in an xmltype variable?
    I don't want to have to use the sql commands update ... set that constrain me to changing XML already stored in a table.
    For example this is what I would like to do. If I have the following XML in clob vXmlClob
    <Action>
    <User>SVOLLMAN</User>
    </Action>
    I want to change the user to Dave...
    declare
    vXmlType xmltype;
    vXmlClob clob;
    begin
    vXmlType := xmltype(vXmlClob);
    vXmlType := xmlType.updatexml('Action/User','Dave');
    end;
    Of course this does not work but is there another way of updating the XML in my variable. Or maybe I am looking at this the wrong way - is there any way of using the update ... set sql commands without having the XML already in a table.

    You mean this?:
    michaels>  select xml, updatexml (d.xml, 'Action/User/text()', 'Dave') updated_xml
      from (select xmltype ('<Action><User>SVOLLMAN</User></Action>') xml from dual) d
    XML                                        UPDATED_XML                          
    <Action><User>SVOLLMAN</User></Action>     <Action><User>Dave</User></Action>                                                                                        

  • XQuery for (CLOB)-XMLType

    I would like to know whether XQuery is supporting XMLType (CLOB).
    It seems to be possible to apply XQuery on a sqlquery by using the command sqlquery(..) according to FOR $b IN sqlquery(..)
    This however throws a parsing excpetion when I use an sql-query that contains the extract statement which is used for CLOBs
    Please help !
    Below a piece of code that is not running..
    FOR $b IN sqlquery("select extract( doc,'/MeasurementSystems/' ).getStringVal() from V34_6jisno7sf3ksve4m5pabk33h1b X")/MeasurementSystems/MeasurementSeries/*

    Marcel,
    Does the extract work outside of the sqlquery and FOR loop?

  • XMLTYPE variable converting to XML (Question)

    Friends,
    I am stuck on an error and cannot find a way out. Please help. I know it's a long question but a very simple answer to many smart people here. I am just lost and need your help. (I am new to SOA so bear with me)
    I have a BPEL process which invokes a PL/SQL API which returns the XMLTYPE output which has the XML data. In order to convert the XMLTYPE to normal XML I do following :-
    - I added a Java embed activity in BPEL with following code (Invoke_new_get_customer_order_info_OutputVariable','OutputParameters','/ns2:OutputParameters/ns2:X_CUSTOMER_ORDER_INFO_XML is the XMLTYPE)
    (responsePayoad is string variable)
    try{                                                           
    Node node = (Node)getVariableData("Invoke_new_get_customer_order_info_OutputVariable','OutputParameters','/ns2:OutputParameters/ns2:X_CUSTOMER_ORDER_INFO_XML");
    Node childNode = (Node) node.getFirstChild();
    StringWriter writer = new StringWriter();
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.transform(new DOMSource(childNode), new StreamResult(writer));
    String xml = writer.toString();
    String nsXML = xml.replaceFirst("<FetchCustomerInfoResponse","<FetchCustomerInfoResponse xmlns=\"http://xmlns.djoglobal.com/OrderTracking/CustomerInfo\" ");
    setVariableData("responsePayload",nsXML);
    addAuditTrailEntry("XML with Namespace: " + nsXML);
    } catch(Exception e){                            
    addAuditTrailEntry(e);
    System.out.println("Namespace injection failed due to : " + e);
    After above I have ASSIGN activity where I use parsexml function on the "responsePayload" variable to assign to a variable of type element which refers to following xsd. This is where I get an "internal xpath error" during runtime which I cannot resolve.
    XSD of the element variable refering to "FetchCustomerInfoResponse" element
    <?xml version="1.0" encoding="windows-1252" ?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.example.org"
    targetNamespace="http://xmlns.djoglobal.com/OrderTracking/DJOFetchCustomerOrderInfo"
    elementFormDefault="qualified">
    <xsd:element name="FetchCustomerInfoResponse">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="DJO_ONT_ACCOUNT_ORDERS">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="DJO_ONT_ACCOUNT_ORDER" maxOccurs="unbounded">
    <xsd:complexType>
    <xsd:attribute name="ordered_date" type="xsd:string"/>
    <xsd:attribute name="cust_po_number" type="xsd:string"/>
    <xsd:attribute name="order_number" type="xsd:integer"/>
    <xsd:attribute name="header_id" type="xsd:integer"/>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>
    XML returned in the XMLTYPE from the PL/SQL API :-
    <Invoke_new_get_customer_order_info_OutputVariable><part name="OutputParameters" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <OutputParameters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/APPS/XXDJO_ONT_ORDER_TRACKING_WS/GET_CUSTOMER_ORDER_INFO_XML/"><X_CUSTOMER_ORDER_INFO_XML>
    <FetchCustomerInfoResponse xmlns="">
    <DJO_ONT_ACCOUNT_ORDERS>
    <DJO_ONT_ACCOUNT_ORDER ordered_date="24-APR-12" cust_po_number="PO1" order_number="123456" header_id="7777777"/>
    <DJO_ONT_ACCOUNT_ORDER ordered_date="19-APR-12" cust_po_number="PO2" order_number="4545454" header_id="888888"/>
    <DJO_ONT_ACCOUNT_ORDER ordered_date="09-APR-12" cust_po_number="PO3" order_number="56565656" header_id="999999"/>
    </FetchCustomerInfoResponse>
    </X_CUSTOMER_ORDER_INFO_XML>
    </OutputParameters></part></Invoke_new_get_customer_order_info_OutputVariable></messages>
    Any help is greatly appreciated as this is driving me nuts.
    Thanks

    Few modifications,
    1. Initialize your int count to 0, int count=0;
    2. Write count++; as the first statement in your for loop. 3. Remove count++; at the bottom.
    4. Add a hidden field to your form (after submit button, but before your </form> tag)
    <input type="hidden" name="qCount" value="<%=count%>">
    Now use this code,
    writeXML.jsp
    <%
    int qCount = Integer.parseInt(request.getParameter("qCount"));
    String home ="C:\\Tomcat\\FYProject\\lib\\";
    String filename = request.getParameter("file");
    String extension = ".xml";
    String filePath = home + filename + extension;
    BufferedWriter bw = new BufferedWriter(new FileWriter(filePath,true));
    bw.write("<mc_QuestionType>");
    bw.newLine();
    for(int count=0;count<qCount;count++) {
         String Tquestion = request.getParameter("questionText"+count);
         String answer1 = request.getParameter("choice_1"+count);
         String answer2 = request.getParameter("choice_2"+count);
         String answer3 = request.getParameter("choice_3"+count);
         String answer4 = request.getParameter("choice_4"+count);
         String Canswer = request.getParameter("cAnswer"+count);
         bw.write(" <questionText>" Tquestion "</questionText>");
         bw.newLine();
         bw.write(" <choice>" answer1 "</choice>");
         bw.newLine();
         bw.write(" <choice>" answer2 "</choice>");
         bw.newLine();
         bw.write(" <choice>" answer3 "</choice>");
         bw.newLine();
         bw.write(" <choice>" answer4 "</choice><br>");
         bw.newLine();
         bw.newLine();
         bw.write(" <answer>" Canswer "</answer>");
         bw.newLine();
         bw.write("</mc_QuestionType>");
         bw.close();
    %>Hope this works.
    Sudha

  • Printing ?xml version="1.0"..? tag in xmltype variable

    I created the xmltype "result" by using xmlelement and xmlforest functions in a select query.
    Now I need to add the "<?xml version="1.0" encoding="utf-8"?>" to the xmltype.
    I tried manipulating the clob (result.getclobval()) using dbms_lob.append() ,dbms_lob.write() and dbms_lob.writeappend() functions in various combinations,but nothing seems to work.
    Can anyone help me with this?
    Thanks,
    Aditi

    Hi,
    I want to strip it off because I am apppending the same in a Java Program.
    Please let me know how can it be done.
    Appreciate your inputs.
    Thanks,
    Dibya

  • Appending XML Node to XMLTYPE Variable

    Hi All,
    My Database Details,
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    PL/SQL Release 9.2.0.1.0 - Production
    CORE 9.2.0.1.0 Production
    TNS for 32-bit Windows: Version 9.2.0.1.0 - Production
    NLSRTL Version 9.2.0.1.0 - Production
    SQL> var mycnt number
    SQL> exec :mycnt := 2
    SQL> declare
    xml xmltype := xmltype('
    <EMP>
    <NAME>
    </NAME>
    <SALARY>
    <DATE></DATE>
    <AMOUNT></AMOUNT>
    </SALARY>
    </EMP>');
    l_sal long := '<SALARY><DATE></DATE><AMOUNT></AMOUNT></SALARY>';
    l_str long;
    begin for i in 1 .. :mycnt
    loop
    l_str := l_str || l_sal;
    end loop;
    xml := xmltype(replace (xml.getstringval(), '</EMP>', l_str || '</EMP>'));
    dbms_output.put_line (xml.extract('.').getstringval());
    end;
    <EMP>
    <NAME/>
    <SALARY>
    <DATE/>
    <AMOUNT/>
    </SALARY>
    <SALARY>
    <DATE/>
    <AMOUNT/>
    </SALARY>
    <SALARY>
    <DATE/>
    <AMOUNT/>
    </SALARY>
    </EMP>
    This program is working fine. Consider the following scenario...
    My XML is like this,
    <ABC>
    <AB> -- First element
    <CCC></CCC>
    </AB>
    <AB> -- Second element
    <CCC></CCC>
    </AB>
    </ABC>
    Now i want to replicate the tag of <CCC></CCC>
    to 'N' TIMES from XPATH = /A/AB[1]/CCC and /A/AB[2]/CCC
    For example if N=3 then, the XML should be,
    <ABC>
    <AB>
    <CCC></CCC>
    <CCC></CCC>
    <CCC></CCC>
    </AB>
    <AB>
    <CCC></CCC>
    <CCC></CCC>
    <CCC></CCC>
    </AB>
    </ABC>
    Please provide me some Sample PLSQL code for this,
    Thanks in Advance,
    Simbhu

    not sure that this is waht you want - but maybe you find smth useful:
    SQL> set serveroutput on;
    SQL>
    SQL> declare str xmltype:=xmltype('<ABC><AB><CCC></CCC></AB><AB><CCC></CCC></AB><AB><CCC></CCC></AB></ABC>');
      2  begin
      3  for i in 1..2
      4  loop
      5  select InsertChildXML(str, '/ABC/AB['||i||']', 'CCC', XMLForest('' as "CCC",'' as "CCC")) into str from dual;
      6  end loop;
      7  dbms_output.put_line(str.extract('.').getstringval());
      8  end;
      9  /
    <ABC>
      <AB>
        <CCC/>
        <CCC/>
        <CCC/>
      </AB>
      <AB>
        <CCC/>
        <CCC/>
        <CCC/>
      </AB>
      <AB>
        <CCC/>
      </AB>
    </ABC>
    PL/SQL procedure successfully completed
    SQL>

  • Xquery against db replica

    The following exception is raised on the replica during xquery processing: Unable to add a URI or prefix string to dictionary. The backtrace is included below. Is there a way to avoid this exception ?
    Thanks again.
    (gdb) bt
    #0 0x00002b28bc762a3d in *__GI_raise (sig=23975)at ../nptl/sysdeps/unix/sysv/linux/raise.c:67
    #1 0x00002b28bc763f1e in *__GI_abort () at ../sysdeps/generic/abort.c:88
    #2 0x00002b28bc363ba8 in __gnu_cxx::__verbose_terminate_handler () from /usr/lib64/libstdc++.so.6
    #3 0x00002b28bc361d86 in __cxa_call_unexpected () from /usr/lib64/libstdc++.so.6
    #4 0x00002b28bc361db3 in std::terminate () from /usr/lib64/libstdc++.so.6
    #5 0x00002b28bc361f01 in __cxa_rethrow () from /usr/lib64/libstdc++.so.6
    #6 0x00002b28bb108f5c in DbXml::NsSAX2Reader::parse (this=0x4130c8b0, source=@0x4130c790) at NsSAX2Reader.cpp:354
    #7 0x00002b28bb10439b in DbXml::NsSAX2Reader::parse (this=0x4130c8b0, is=0x8e5258) at NsSAX2Reader.cpp:322
    #8 0x00002b28bb07c3d8 in DbXml::Document::stream2dom (this=0x8e5160, txn=0x8cc610, includeEntityInfo=false) at Document.cpp:960
    #9 0x00002b28bb07e969 in DbXml::Document::getContentAsDOM (this=0x8e5160) at Document.cpp:591
    #10 0x00002b28bb0e8947 in DbXml::IndexEntry::fetchNode (this=0x8e4220, document=0x8e5160) at IndexEntry.cpp:117
    #11 0x00002b28bb148cb4 in DbXml::DbXmlNodeImpl::getAxisDbXmlResult (this=0x8e50e0, axis=XQStep::FOLLOWING, nt=0x8acbb8, context=0x6, location=0x8e4150) at SharedPtr.hpp:68
    #12 0x00002b28bb15a209 in QueryPlanStepResult::setResult (this=0x8e4140, node=0x5dc1, context=0x6) at DbXmlStep.hpp:38
    #13 0x00002b28bb15b629 in DbXml::QueryPlanResultImpl::nextResult (this=0x8e4140, item=@0x4130ccb0, context=0x8a87b8) at QueryPlanResultImpl.cpp:151
    #14 0x00002b28bb15be6d in DbXml::QueryPlanResultImpl::next (this=0x8e4140, context=0x8a87b8) at QueryPlanResultImpl.cpp:165
    #15 0x00002b28bb153ad0 in DbXml::DbXmlFilter::FilterResult::next (this=0x8e41e0, context=0x8a87b8) at DbXmlResult.hpp:118
    #16 0x00002b28bb492f89 in XQQuery::QueryResult::next () from /usr/local/maui/lib/libxqilla.so.1
    #17 0x00002b28bb08fd76 in DbXml::LazyDIResults::hasNext (this=0x8ab220) at Result.hpp:81
    #18 0x00002b28bb0a6609 in DbXml::XmlResults::hasNext (this=0x5da7) at XmlResults.cpp:74
    ...

    This is a known issue in BDB XML 2.3.10. You can try 2.4.11 or wait for a soon-to-be-released roll-up patch for 2.3.
    Regards,
    George

  • ADF BC against XMLDB XMLType

    XMLType object based storage provide updateXML(), InsertChildXML(), appendChildXML() deleteXML() methods.
    Are these methods generated natively in ADF BC ?
    Is it somewhere described how XML DB is implemented in ADF BC ?

    Please see my reply in your similar thread in the XMLDB forum. Thanks.
    XML DB vs Berkeley XML

  • Selective extraction from an xmltype variable

    I have a fragment of XML -
    <Unit name="MAIN UNIT">
    <Ops event_type="U1" cause_code="7050" begin_time="2003-06-13T09:38:00">Broken restoring cable</Ops>
         <Ops event_type="GE" cause_code="0001" begin_time="2003-06-03T07:07:03"/>
    <Generation begin_time="2003-06-13T00:00:00" end_time="2003-06-13T23:59:59" mwh_produced="229.00" mwh_consumed="0.00"/>
    </Unit>
    I am trying to extract just the text of an "Ops" fragment. In the above case, the first would be "Broken restoring cable" and the second would be NULL. Using
    v_belement.extract('/Ops').getStringVal()
    inside of a loop through the array gives me the entire fragment. How can I get just the text?
    Bill

    Bill,
    Try extractValue instead of extract.
    Bharathi

  • (urgent) How to make sumarize query against XMLType?

    Hello,
    i have xml document like this
    <List>
    <Item>
    <A>10</A>
    <B>554</B>
    <C>25.5.2005</C>
    </Item>
    <Item>
    <A>20</A>
    <B>49</B>
    <C>26.5.2005</C>
    </Item>
    <Item>
    <A>30</A>
    <B>184</B>
    <C>27.5.2005</C>
    </Item>
    </List>
    in xmltype variable (not table column) and i need e.g. sum (or count or something like that) values in xpath /List/Item/B in one document.
    Is there some quick and elegant way to do this?
    Thanks for quick help.

    Maybe the below will help.
    Did you look at building a view over the xmltype extracting the values into a relational type view, then using the view to sum up the values.
    Jonthan Gennick has an article on the Oracle OTN website with the below code.
    CREATE VIEW cd_master (Title, Artist, Website, Description) AS
    SELECT extractValue(value(x),'/CD/Title'),
    extractValue(value(x),'/CD/Artist'),
    extractValue(value(x),'/CD/Website'),
    extractValue(value(x),'/CD/Description')
    FROM CD331_TAB x;
    CREATE INDEX by_artist ON CD331_TAB x (
    extractValue(value(x),'/CD/Artist'));
    ANALYZE TABLE cd331_tab COMPUTE STATISTICS FOR TABLE;
    ANALYZE INDEX by_artist COMPUTE STATISTICS;

  • Is it possible to add variable defined as xmltype to an xmldom node?

    Hi,
    I'm trying to produce a complex XML document that doesn't lend itself well to using SQL XML functions (xmlagg, xmlelement, etc.) because various disparate data needs to be pulled together via seperate queries and then stuck into the final document in the correct spots.
    So I've resorted to using the convoluted pl/sql xmldom functions. What I'm wondering though is if it is possible to take data in an xmltype variable and somehow append it as a node within my xml document? Something as in the following pseudo code:
    begin
    doc := xmldom.newDOMDocument;
    main_node := xmldom.makeNode (doc);
    select xmlelement("Address",...) -- more xmlelements containing related address info (street, city, etc.)
    into l_address
    from ...;
    new_node := xmldom.appendChild (main_node, xmldom.makeNode (l_address));
    end;
    If possible, this would save me a tremendous amount of time from having to code every element and attributes via the xmldom functions.
    Thanks,
    Alan

    I've done the same scenario you are describing, shove XML defined in an XMLType into a DOMDocument. I munged the code to hide system specific references so the code works, just not as pasted here. The document is being built in o_response_doc and goes after the node previously built in l_rsp_msg_nd. The input is l_xmltype. May be a better way but I never found one and came up with this based on the Oracle documentation and trial and error.
        -- Convert the XMLType to a DOMDocument so we can extract the needed node
        --  and insert it into the response DOMDocument
        l_temp_domdoc := dbms_xmldom.newdomdocument(l_xmltype);
        l_inq_nodelist := dbms_xmldom.getelementsbytagname(l_temp_domdoc,
                                                           'DesiredXMLTypeNodeName');
        l_inq_nl_len := xmldom.getlength(l_inq_nodelist);
        IF l_inq_nl_len > 0 THEN
           -- Take the node above and adopt it into the response document
           l_temp2_nd := dbms_xmldom.importNode(o_response_doc,
                                                dbms_xmldom.item(l_inq_nodelist, 0),
                                                TRUE);
           -- Remove the a: namespace that was autoadded.  (this was defined in the l_xmltype XML)
           dbms_xmldom.removeattribute(dbms_xmldom.makeelement(l_temp2_nd),
                                       <ns_pfx>,
                                       <ns_uri>);
           -- Put the node in the correct position in the response document                                          
           l_temp2_nd := xdb.dbms_xmldom.appendChild(l_rsp_msg_nd, l_temp2_nd);
        END IF;
        dbms_xmldom.freeDocument(l_temp_domdoc);

  • XPath query against XMLType

    Hello,
    I am trying to reproduce the following XPath query using XDB functionality against a XMLType column:
    //AtomicPart[@MyID='190' or @MyID='495' or @MyID='1662']
    If I do the following I do get all AtomicParts:
    select X.xml.extract('//AtomicPart') FROM TEST X
    But I havent figured out how to do the or operation. Is it possible or does it require views?
    Thank you,
    Robert

    Robert
    Need to see the instance document in order to answer this..

  • Validating XML against an XML Schema using PL/SQL

    Hello everyone,
    I've a strange problem.
    I'm trying to validate an XMLTYPE variable against an XSD schema using the XMLisValid function.
    The XML I was trying to validate was returning false (0) when using this method.
    However, when I register the XSD against a column in a table and then insert this XMLTYPE into that column, I do not get any errors. If I change the XSD to ensure failure when using this method, I do get an error, so it is registered and working.
    I have then created a very basic XSD and both methods work when validating the XML against this. So obviously the more complicated XSD I want to validate against is making a difference, but I would expect them to either both fail or both pass, not one fail and one pass.
    Does anyone know why they'd be returning different results?
    Thanks in advance for your help.
    Robin
    examples of what I'm using:
    XML to validate:
    <centres>
    <add>
    <centre>
    <centreName>Name 1</centreName>
    <centreRef>45678</centreRef>
    </centre>
    </add>
    </centres>
    Simple XSD:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="centres" type="centresType"/>
    <xs:complexType name="addType">
    <xs:sequence>
    <xs:element type="xs:string" name="centreName"/>
    <xs:element type="xs:short" name="centreRef"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="centresType">
    <xs:sequence>
    <xs:element type="addType" name="add" maxOccurs="3" minOccurs="0"/>
    </xs:sequence>
    </xs:complexType>
    </xs:schema>
    Complicated XSD:
    <?xml version="1.0" encoding="utf-8" ?>
    <!--Created with Liquid XML Studio - 30 Day Trial Edition 7.1.6.1440 (http://www.liquid-technologies.com)-->
    <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="centres">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="remove">
    <xs:complexType>
    <xs:sequence>
    <xs:element minOccurs="0" maxOccurs="1000" name="centreRef">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:minLength value="1" />
    <xs:maxLength value="50" />
    </xs:restriction>
    </xs:simpleType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name="add">
    <xs:complexType>
    <xs:sequence>
    <xs:element minOccurs="0" maxOccurs="1000" name="centre">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="centreName">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:minLength value="1" />
    <xs:maxLength value="100" />
    </xs:restriction>
    </xs:simpleType>
    </xs:element>
    <xs:element name="centreRef">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:minLength value="1" />
    <xs:maxLength value="50" />
    </xs:restriction>
    </xs:simpleType>
    </xs:element>
    <xs:element minOccurs="0" maxOccurs="1" name="qualifications">
    <xs:complexType>
    <xs:sequence>
    <xs:element minOccurs="0" maxOccurs="1000" name="qualRef">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:minLength value="1" />
    <xs:maxLength value="100" />
    </xs:restriction>
    </xs:simpleType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name="modifyQualAssociations">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="remove">
    <xs:complexType>
    <xs:sequence>
    <xs:element minOccurs="0" maxOccurs="1000" name="r">
    <xs:complexType>
    <xs:attribute name="centreRef" use="required">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:minLength value="1" />
    <xs:maxLength value="50" />
    </xs:restriction>
    </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="qualRef" use="required">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:minLength value="1" />
    <xs:maxLength value="100" />
    </xs:restriction>
    </xs:simpleType>
    </xs:attribute>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name="add">
    <xs:complexType>
    <xs:sequence>
    <xs:element minOccurs="0" maxOccurs="1000" name="a">
    <xs:complexType>
    <xs:attribute name="centreRef" use="required">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:minLength value="1" />
    <xs:maxLength value="50" />
    </xs:restriction>
    </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="qualRef" use="required">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:minLength value="1" />
    <xs:maxLength value="100" />
    </xs:restriction>
    </xs:simpleType>
    </xs:attribute>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>

    Steps to validate XML data against a schema in Oracle:
    1. Register your XSD in the database.
    begin
    dbms_xmlschema.registerschema(
    SchemaUrl,
    SchemaDoc,
    local => TRUE/FALSE);
    end;
    2. For validating your XML document against your registered schema, here is a sample pl/sql block.
    declare
    v_xml xmltype;
    begin
    v_xml := your_xml_document;
    v_xml.schemaValidate();
    end;
    Hope this helps :)

Maybe you are looking for

  • Wlan MAC in deep sleep. Please help debug

    Hi, I have begun experiencing a most distrubing error with my wlan0 recently (perhaps within the last week; at the most 14 days).  My wlan0 stops working and disconnect entirely from the system for some to me unknown reason. Here is a bit from my /va

  • Masked HTML tags in substitution strings after upgrade to Apex 2.2

    Hello,<br> <br> in my application developed with htmldb 2.0 I had the following scenario which worked fine until upgrade to 2.2:<br> <br> Requirement: a multiline text should be displayed as entered on a html report page.<br> My solution:<br> - a onl

  • Developer 6.0 or Developer 2000

    Can anyone tell me what's the difference between Developer 6.0 and Developer 2000? I'm new on Oracle development and trying to figure out which one I should install on my PC. I've read through many posted topics but could figure it out from those mes

  • Mobile Browser and LOV

    Hello, I have a mobile browser application to develop and I need something like a LOV mechanism. I saw that the inputListOfValues tag is not supported. I can't use the selectOneChoice for all the fields since they may be very big (in terms of data re

  • Help resolve please

    Hi all, Please can anyone help with resolving the errors below? SQL> shutdown abort ORACLE instance shut down. SQL> startup mount ORACLE instance started. Total System Global Area 118255568 bytes Fixed Size 282576 bytes Variable Size 83886080 bytes D