Problem in XPath query with namespace

Hi All,
Please help me on this topic.I given xml document which i have inserted into Oracle XML DB 10g R2 without registering xml schema.
I am listing out my problem here.
1. I need to get the value of cost element.If i have parent node duplicate
<?xml version="1.0" ?>
<customers xmlns="http://localhost/openuri.org" >
<customer xmlns="http://orcl.com">
<order>
<ordername>Computer</ordername>
<cost>35785638</cost>
</order>
<order>
<ordername>Computer</ordername>
<cost>35785638</cost>
</order>
</customer>
</customers>
2. The leaf node has namespace in it.How do i write query for second cost element.
<?xml version="1.0" ?>
<customers xmlns="http://localhost/openuri.org" >
<customer xmlns="http://orcl.com">
<order>
<ordername>Computer</ordername>
<cost>35785638</cost>
</order>
<order>
<ordername>Computer</ordername>
<cost xmlns="http://oracle.xdb.com">35785638</cost></order>
</customer>
</customers>
Thanks in Advance,
James

set long 100000
var xmltext clob
begin
:xmltext:=
'<?xml version="1.0" ?>
<customers xmlns="http://localhost/openuri.org" >
     <customer xmlns="http://orcl.com">
          <order>
               <ordername>Computer</ordername>
               <cost>35785638</cost>
          </order>
          <order>
               <ordername>Computer</ordername>
               <cost>35785638</cost>
          </order>
     </customer>
</customers>';
end;
select rownum as "NUM"
,      extractvalue(value(v),'/*') as "VALUE"
from   table(xmlsequence(extract(xmltype(:xmltext),'//customer/order/cost','xmlns="http://orcl.com"'))) v
SQL> r
  1  select rownum as "NUM"
  2  ,      extractvalue(value(v),'/*') as "VALUE"
  3  from   table(xmlsequence(extract(xmltype(:xmltext),'//customer/order/cost','xmlns="http://orcl.com"'))) v
  4*
       NUM VALUE
         1 35785638
         2 35785638
begin
:xmltext:=
'<?xml version="1.0" ?>
<customers xmlns="http://localhost/openuri.org" >
     <customer xmlns="http://orcl.com">
          <order>
               <ordername>Computer</ordername>
               <cost>35785638</cost>
          </order>
          <order>
               <ordername>Computer</ordername>
               <cost xmlns="http://oracle.xdb.com">35785638</cost></order>
     </customer>
</customers>';
end;
select extractvalue(xmltype(:xmltext),'//cost','xmlns="http://oracle.xdb.com"')
from dual;
SQL> r
  1  select extractvalue(xmltype(:xmltext),'//cost','xmlns="http://oracle.xdb.com"')
  2* from dual
EXTRACTVALUE(XMLTYPE(:XMLTEXT),'//COST','XMLNS="HTTP://ORACLE.XDB.COM"')
35785638
select *
from table(xmlsequence(extract(xmltype(:xmltext),'//cost','xmlns="http://oracle.xdb.com"')))
SQL> r
  1  select *
  2  from table(xmlsequence(extract(xmltype(:xmltext),'//cost','xmlns="http://oracle.xdb.com"')))
  3*
COLUMN_VALUE
<cost xmlns="http://oracle.xdb.com">35785638</cost>
select extractvalue(value(v),'/*')  "VALUE"
from table(xmlsequence(extract(xmltype(:xmltext),'//cost','xmlns="http://oracle.xdb.com"'))) v
SQL> r
  1  select extractvalue(value(v),'/*')  "VALUE"
  2  from table(xmlsequence(extract(xmltype(:xmltext),'//cost','xmlns="http://oracle.xdb.com"'))) v
  3*
VALUE
35785638
select *
from table(xmlsequence(extract(xmltype(:xmltext),'//customer/order','xmlns="http://orcl.com"')))
SQL> r
  1  select *
  2  from table(xmlsequence(extract(xmltype(:xmltext),'//customer/order','xmlns="http://orcl.com"')))
  3*
COLUMN_VALUE
<order xmlns="http://orcl.com">
  <ordername>Computer</ordername>
  <cost>35785638</cost>
</order>
<order xmlns="http://orcl.com">
  <ordername>Computer</ordername>
  <cost xmlns="http://oracle.xdb.com">35785638</cost>
</order>

Similar Messages

  • XPath query with out namespace is possible ?

    Hi,
    our system reciving xml data using the datatype xsd[b] &lt;any/&gt; . am sure the system will receive the data in same format[node hierarchical] but the namespace of the root element may be differ..
    i want write xpath which should not be parse based on the namespace of element.
    like the method setNameSpaceAware(false) in java;
    will it be possible in bpel. if so how ?
    i would be appreciate any help.
    Thanks,
    Bogi

    Ahhhh - thank you for the clarification.
    Regarding the expansion of variable, is there anything further needed? Reason I ask is, when I use the variable which contains the same string as when I hard code the string in the XPATH query, I do not receive the desired results - I only receive the
    'VENDOR_ADVISORY' results.

  • XPath processing with namespaces does not work. Please review my code..

    Dear all,
    I am working on with the IMS Group's Enterprise XML standard (http://www.imsproject.org/enterprise/) and need to retrieve member information using XPath.
    After significant fault finding, I have narrowed down the problem to the XML file containing multiple namespaces in the root element. I have checked out some forum postings here and on Google (programmer's best friend) for possible solutions... namely the implementation of the my own NamespaceContext object. I have implemented and yet I am still not able to retrieve the data I want.
    Could someone advise where I am going wrong?
    When I remove the namespaces from the root element I can find out the number of member elements in the XML (just for testing atm). I could write a regular expression to remove the namespaces from my XML, but that's just dodgy..
    Here's a sample XML:
    <enterprise xmlns="http://www.imsproject.org/xsd/imsep_rootv1p01" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:webct="http://www.webct.com/IMS">
    <properties>...</properties>
    <group>...</group>
    <membership>
    <member>...</member>
    </membership>
    </enterprise>
    My implementation of the a NamespaceContext object:
    public class IMSProjectNamespaceContext implements NamespaceContext {
    public String getNamespaceURI(String prefix) {       
    if(prefix == null) throw new NullPointerException("Null prefix");
    else if("xsi".equals(prefix)) return "http://www.w3.org/2001/XMLSchema-instance";
    else if("webct".equals(prefix)) return "http://www.webct.com/IMS";
    else if("xml".equals(prefix)) return XMLConstants.XML_NS_URI;
    return XMLConstants.NULL_NS_URI;
    }// end of overriding getNamespaceURI method
    // This method is not necessary for XPath processing
    public String getPrefix(String uri) {
    throw new UnsupportedOperationException();
    }// end of overriding getPrefix method
    // This method is not necessary for XPath processing
    public java.util.Iterator getPrefixes(String uri) {
    throw new UnsupportedOperationException();
    }// end of overriding getPrefixes method
    }// end of IMSProjectNamespaceContext class
    My method attempting to use XPath... but not successful (it should print out the number of member elements if XPath works correctly with my XML file, but only prints out 0 each time):
    private void getSectionMembers(String dataXML) throws Exception {
    try {       
    InputSource inputSource = new InputSource(new StringReader(dataXML));
    XPath xPath = XPathFactory.newInstance().newXPath();
    xPath.setNamespaceContext(new IMSProjectNamespaceContext());
    XPathExpression xPathExpression = xPath.compile("/enterprise/membership/member");
    NodeList nodes = (NodeList)xPathExpression.evaluate(inputSource, XPathConstants.NODESET);
    System.out.println(nodes.getLength()); // Debugging
    } catch(Exception ex) {
    ex.printStackTrace();
    throw new Exception("XPath Querying Failed.");
    }// end of xPathQuery method

    Dear dvohra09,
    Thank you for your quick reply. Much appreciated. I have implemented a NamespaceContext object that is able to set more than one prefix for a URI as you suggested.
    It works when I remove the first namespace that is generated in the IMSProject Enterprise XML:
    xmlns="http://www.imsproject.org/xsd/imsep_rootv1p01"
    When I hack the XML and set a prefix for this ('default') namespace it works... For example:
    xmlns:ims="http://www.imsproject.org/xsd/imsep_rootv1p01"
    Is the NamespaceContext class supposed to handle for so called "default" namespaces (without needing to touch the XML)?
    My method is performing the XPath query is below:
    private void getSectionMembers(String dataXML) throws Exception {
    try {       
    InputSource inputSource = new InputSource(new StringReader(dataXML));
    IMSProjectNamespaceContext imsproject = new IMSProjectNamespaceContext();
    imsproject.setNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    imsproject.setNamespace("webct", "http://www.webct.com/IMS");
    imsproject.setNamespace("ims", "http://www.imsproject.org/xsd/imsep_rootv1p01lme");
    XPath xPath = XPathFactory.newInstance().newXPath();
    xPath.setNamespaceContext(imsproject);
    XPathExpression xPathExpression = xPath.compile("//ims:enterprise/@xmlns/text()");
    NodeList nodes = (NodeList)xPathExpression.evaluate(inputSource, XPathConstants.NODESET);
    System.out.println(nodes.getLength()); // Debugging
    System.out.println(nodes.item(0).getNodeValue()); // Debugging
    } catch(Exception ex) {
    ex.printStackTrace();
    throw new Exception("XPath Querying Failed.");
    }// end of xPathQuery method
    Regards
    Zig

  • Problem in SAP Query with currency conversion   based on table TCURX

    Hi All,
    I have an infoset where tables A903 and KONP are joined . Query is displaying the KONP-KBTER values with currency as stored in the database table .My requirement is to show the KBETR value as per decimals stored in TCURX table for that currency .
    For Example If KONP-KBETR = 51.29 JPY , It sholuld display as 5129  as  Decimal places for JPY is 0.
    There is FM CURRENCY_AMOUNT_SAP_TO_DISPLAY Which gives the equvivalent display value to the databse value value.But it is giving dump because of type conflict with
    KONP-KBETR .
      Can any body help me how can i solve the problem in My Query ? .Pls any small idea taht may help greatly  also warmly welcome .
    Thx,
    Dharma .

    Hi Sriram ,
    But how can i use it in Queries . I mean should I go for a additional filed in infoset and then passing the  converted value to the the that additional field .
    Thx ,
    Dharma .

  • URGENT!Problem running a Query with a Subquery that includes the same table

    Hello all,
    Currently we are working over Oracle Database 10g Release 2 (10.2.0.3) Patch Set1.
    We have registered a schema called ICRI and we have created two VIEW over this schema to work in some occasions.
    CREATE OR REPLACE VIEW "ICRI_RELACIONAL_VIEW"
    (IDICRI, NOMBRERECURSO, VERSIONRECURSO) AS
    SELECT extractValue(value(i), '/ICRI/ID/text()'),
           extractValue(value(i), '/ICRI/NombreRecurso/text()'),
           extractValue(value(i), '/ICRI/VersionRecurso/text()') || '.' || extractValue(value(m), '/Modificacion/Secuencia/text()'),
    FROM ICRI i, table(xmlsequence(extract(value(i), '/ICRI/Modificaciones/Modificacion'))) m
    WHERE extractValue(value(m), '/Modificacion/Secuencia/text()') =
          (SELECT max(extractValue(value(s), '/Secuencia/text()'))
           FROM table(xmlsequence(extract(value(i),'/ICRI/Modificaciones/Modificacion/Secuencia'))) s)
    WITH READ ONLY;
    CREATE OR REPLACE VIEW "ICRI_DOMINIOS_VIEW"
    (ID, DOMINIO) AS
    SELECT extractValue(value(i), '/ICRI/ID/text()'),
           extractValue(value(a), '/Dominio/text()', 'xmlns="http://www.orswegimoarmada.es/ORSWE/ICRI"')
    FROM ICRI i, table(xmlsequence(extract(value(i), '/ICRI/Dominios/Dominio'))) a
    WITH READ ONLY;We have created 5000 XML documents based in this schema and stored in the database.
    Now we have executed different querys to obtain certain data.
    * QUERY 1
    SELECT COUNT(*) FROM ICRI_DOMINIOS_VIEW V1, ICRI_DOMINIOS_VIEW V2
    WHERE V1.ID = V2.ID AND V1.DOMINIO = 'Mar' AND V2.DOMINIO = 'Tierra'Time: 38sg. 1 row, Value: 1097.
    * QUERY 2
    SELECT COUNT(*) FROM ICRI_DOMINIOS_VIEW V1
    WHERE V1.DOMINIO = 'Mar'
          AND
          V1.ID IN (SELECT V2.ID FROM ICRI_DOMINIOS_VIEW V2
                    WHERE V2.DOMINIO = 'Tierra')Time: 34sg. 1 row, Value: 1097.
    * QUERY 3 (XPath Version)
    SELECT COUNT(*)
    FROM ICRI
    WHERE existsNode(object_value, '/ICRI/Dominios[Dominio="Mar" and Dominio="Tierra"]')=1
    Time: 32msg. 1 row, Value: 1097.
    * QUERY 4 (Version XPath)
    SELECT extractValue(object_value, '/ICRI/ID/text()')
    FROM ICRI
    WHERE existsNode(object_value, '/ICRI/Dominios[Dominio="Mar" and Dominio="Tierra"]')=1
    Time: 63mseg. 1097 rows.
    * QUERY 5
    SELECT V1.ID FROM ICRI_DOMINIOS_VIEW V1, ICRI_DOMINIOS_VIEW V2
    WHERE V1.ID = V2.ID AND V1.DOMINIO = 'Mar' AND V2.DOMINIO = 'Tierra'
    Time: 15sg. 1097 rows.
    * QUERY 6
    SELECT V1.ID FROM ICRI_DOMINIOS_VIEW V1
    WHERE V1.DOMINIO = 'Mar'
    AND
    V1.ID IN (SELECT V2.ID FROM ICRI_DOMINIOS_VIEW V2
    WHERE V2.DOMINIO = 'Tierra')
    Time: 26sg. 1097 rows.
    Now, with the next query, we have found an important issue in Oracle, because this query doesn't return any row.
    * QUERY 7
    SELECT extractValue(value(i), '/ICRI/ID/text()') ID,
           extractValue(value(i), '/ICRI/NombreRecurso/text()') NOMBRE,
           extractValue(value(i), '/ICRI/VersionRecurso/text()') || '.' || extractValue(value(m), '/Modificacion/Secuencia/text()') VERSION
    FROM ICRI i, table(xmlsequence(extract(value(i), '/ICRI/Modificaciones/Modificacion'))) m
    WHERE
       (extractValue(value(m), '/Modificacion/Secuencia/text()') =
        (SELECT max(extractValue(value(s), '/Secuencia/text()'))
         FROM table(xmlsequence(extract(value(i),'/ICRI/Modificaciones/Modificacion/Secuencia'))) s)
    AND
       (extractValue(value(i), '/ICRI/ID/text()') IN
        (select extractValue(object_value, '/ICRI/ID/text()') ID
         FROM ICRI
         WHERE (existsNode(object_value, '/ICRI/Dominios[Dominio="Mar" and Dominio="Tierra"]')=1)
    )Time 607mseg. 0 rows.
    * QUERY 8
    SELECT VI.IDICRI, VI.NOMBRERECURSO, VI.VERSIONRECURSO
    FROM ICRI_RELACIONAL_VIEW VI, (SELECT V1.ID FROM ICRI_DOMINIOS_VIEW V1, ICRI_DOMINIOS_VIEW V2
                                   WHERE V1.ID = V2.ID AND V1.DOMINIO = 'Mar' AND V2.DOMINIO = 'Tierra') V3
    WHERE VI.IDICRI = V3.ID Time: 16sg. 1097 rows.
    * QUERY 9
    SELECT VI.IDICRI, VI.NOMBRERECURSO, VI.VERSIONRECURSO
    FROM ICRI_RELACIONAL_VIEW VI
    WHERE VI.IDICRI IN
    (SELECT V1.ID FROM ICRI_DOMINIOS_VIEW V1
    WHERE V1.DOMINIO = 'Mar'
          AND
          V1.ID IN (SELECT V2.ID FROM ICRI_DOMINIOS_VIEW V2
                    WHERE V2.DOMINIO = 'Tierra')Time: 34 sg. 1097 rows.
    * QUERY 10
    SELECT extractValue(value(i), '/ICRI/ID/text()') ID,
    extractValue(value(i), '/ICRI/NombreRecurso/text()') NOMBRE,
    extractValue(value(i), '/ICRI/VersionRecurso/text()') || '.' || extractValue(value(m), '/Modificacion/Secuencia/text()') VERSION
    FROM ICRI i, table(xmlsequence(extract(value(i), '/ICRI/Modificaciones/Modificacion'))) m,
    (SELECT V1.ID FROM ICRI_DOMINIOS_VIEW V1, ICRI_DOMINIOS_VIEW V2
    WHERE V1.ID = V2.ID AND V1.DOMINIO = 'Mar' AND V2.DOMINIO = 'Tierra') V3
    WHERE
    (extractValue(value(m), '/Modificacion/Secuencia/text()') =
    (SELECT max(extractValue(value(s), '/Secuencia/text()'))
    FROM table(xmlsequence(extract(value(i),'/ICRI/Modificaciones/Modificacion/Secuencia'))) s)
    AND
    extractValue(value(i), '/ICRI/ID/text()') = V3.ID
    Time: 15sg. 1097 rows.
    * QUERY 11
    SELECT extractValue(value(i), '/ICRI/ID/text()') ID,
           extractValue(value(i), '/ICRI/NombreRecurso/text()') NOMBRE,
           extractValue(value(i), '/ICRI/VersionRecurso/text()') || '.' || extractValue(value(m), '/Modificacion/Secuencia/text()') VERSION
    FROM ICRI i, table(xmlsequence(extract(value(i), '/ICRI/Modificaciones/Modificacion'))) m
    WHERE
       (extractValue(value(m), '/Modificacion/Secuencia/text()') =
        (SELECT max(extractValue(value(s), '/Secuencia/text()'))
         FROM table(xmlsequence(extract(value(i),'/ICRI/Modificaciones/Modificacion/Secuencia'))) s)
    AND
       (extractValue(value(i), '/ICRI/ID/text()') IN (SELECT V1.ID FROM ICRI_DOMINIOS_VIEW V1
                                                      WHERE V1.DOMINIO = 'Mar'
                                                      AND
                                                      V1.ID IN (SELECT V2.ID FROM ICRI_DOMINIOS_VIEW V2
                                                                WHERE V2.DOMINIO = 'Tierra'))
    )Time: 30sg. 1097 rows.
    * QUERY 12
    SELECT extractValue(value(i), '/ICRI/ID/text()') ID,
           extractValue(value(i), '/ICRI/NombreRecurso/text()') NOMBRE,
           extractValue(value(i), '/ICRI/VersionRecurso/text()') || '.' || extractValue(value(m), '/Modificacion/Secuencia/text()') VERSION
    FROM ICRI i, table(xmlsequence(extract(value(i), '/ICRI/Modificaciones/Modificacion'))) m
    WHERE
       (extractValue(value(m), '/Modificacion/Secuencia/text()') =
        (SELECT max(extractValue(value(s), '/Secuencia/text()'))
         FROM table(xmlsequence(extract(value(i),'/ICRI/Modificaciones/Modificacion/Secuencia'))) s)
       )Time: 187msg. 5000 rows.
    Well, if we execute the query based in a relational view all work fine but the performance of the query is hugely decreased. If we try to execute the query based in the XPath values, this options must be the correct, the query doesn't return any result.
    Any idea to solve this problem? For us it is very important to find a solution as soon as possible, because our development time is finishing.
    Our clients have installed Oracle Client 10.2.0.1 & ODAC 10.2.0.20.
    Thanks in advance for your help,
    David.

    SQL> alter session set optimizer_features_enable='10.1.0';
    Session altered.
    SQL> SELECT count(*)
    2 FROM ICRI i, table(xmlsequence(extract(value(i), '/ICRI/Modificaciones/Mo
    dificacion'))) m
    3 WHERE
    4 extractValue(value(i), '/ICRI/ID/text()') IN
    5 (select extractValue(object_value, '/ICRI/ID/text()') ID
    6 FROM ICRI
    7 WHERE (existsNode(object_value,
    8 '/ICRI/Dominios[Dominio="Mar" and Dominio="Tierra"]')=1))
    9 /
    COUNT(*)
    5
    Test this with a few of your queries and see if the results are expected.
    if so I am thinking it is close to bug 5585187
    QUERY NOT RETURNING PROPER RESULTS WITH INLINE VIEWS
    Fixed in 11.
    I am going to see if I can get an env to see if your TC works with this fix before I confirm it 100 percent.
    Also note this was done with a very scaled down version of your testcase. Using only one XML doc
    regards
    Coby
    Message was edited by: Coby
    coadams

  • VERY URGENT: problem in sql query with long datatype in weblogic

    I have a problem while tryind to retrieve a column value with a long datatype using servlet and oci driver and the server is weblogic5.1 .I have used prepared statement the problem comes in the
    preparedStatement.executeQuery().
    The sql Query is simple query and runs well in all cases and fails only when the long datatype column is included in the query.
    The exception that comes on the weblogic server is that :
    AN UNEXPECTED EXCEPTION DETECTED IN THE NATIVE CODE OUTSIDE THE VM.

    Did you try changing the driver then?
    Please use Oracle's thin driver instead of the oci driver.
    There are many advantages of using the type 4 driver. the first and foremost being that it does not require oracle client side software on your machine. Therefore no enteries to be made in tnsnames.ora
    The thin driver is available in a jar called classes112.zip the class which implements the thin driver is oracle.jdbc.driver.OracleDriver
    the connection string is
    jdbc:oracle:thin:@<machine name>:1521:<sid>
    please try out with the thin driver and let me know.
    regards,
    Abhishek.

  • Query with namespaces

    Hello,
    the issue is that when I make the query the objects returned are 0.
    The registries are like this:
    <Invoice
    xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
    xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
    xmlns:udt="urn:un:unece:uncefact:data:specification:Unqualifi
    edDataTypesSchemaModule:2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
    instance" xmlns:ccts="urn:un:unece:uncefact:documentation:2"
    xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2"
    xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
    <cbc:UBLVersionID>2.0</cbc:UBLVersionID>
    <cbc:CustomizationID>CCIUBL</cbc:CustomizationID>
    <cbc:ProfileID>urn:invinet:profile:solofac-1.0</cbc:ProfileID>
    <cbc:ID>0-2007</cbc:ID>
    <cbc:CopyIndicator>false</cbc:CopyIndicator>
    <cbc:IssueDate>2007-04-01</cbc:IssueDate>
    <cbc:InvoiceTypeCode>Comercial</cbc:InvoiceTypeCode>
    </Invoice>
    I have defined the 'cbc' namespace:
    dbxml> setNamespace "cbc"
    "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
    And the query is, for example:
    dbxml> query 'collection("invoices1.dbxml")/Invoice/cbc:ID'
    0 objects returned for eager expression 'collection("invoices1.dbxml")/Invoice/cbc:ID'
    This example, without the 'cbc' namespace, works correctly.
    Thanks.

    Hi,
    I just tried this on my system using version 2.3.10 creating a default container in the shell (IN).
    Here is what I got:
    dbxml> query 'collection("forum1")/Invoice/cbc:ID'
    Query - Starting query execution
    Query - forum1 - U : [1] 2
    Query - Finished query execution, time taken = 23.747ms
    1 objects returned for eager expression 'collection("forum1")/Invoice/cbc:ID'
    dbxml> print
    <cbc:ID xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">0-2007</cbc:ID>
    Did the setNamespace report any errors? Are you using the current version?
    Ron

  • Problem: Jstl update query with Jquery script

    Hi all,
    i'm writing a jsp page with this 3 star rating Jquery script to show and vote some <div> (results) .
            <script type="text/javascript">
                                        jQuery(document).ready(function($) {
                                            $("#${Rss.pages_id}").stars({
                                                cancelShow: false,
                                                captionEl: $("#<%=i%>"),
                                                callback: function(ui, type, value){
                                                    alert("Callback! ID = ${Rss.pages_id} Clicked: " + type + ", value: " + value );
                                            $("#${Rss.pages_id}").stars("select", ${Rss.trust_value})
                                    </script>Now i want update the value in my DB(MySql) everytime that i will click on my "star rating"..i want do this with an jstl update query.
    Someone can help me?? Thanks

    Just so as you remember that jquery/javascript is completely client side.
    JSP/JSTL is completely server side.
    The only way to invoke java/JSP from javascript code is to make an http request - normally via ajax.
    Given that, it doesn't make sense to put jquery code and a JSTL update query within the same JSP page.
    The code to update the database should be a seperate resource called by ajax from the main page.
    In that case, it doesn't have to be (and probably shouldn't be) done with JSTL. It is better done with java code within servlet/beans.
    cheers,
    evnafets

  • Problem executing a query with AND and OR statements

    I have no idea what is the correct way to implement this part. If the user enters more than one keyword. Then I need to check it using the clause WHERE and AND in my sql statements. Obviously, the attempt I make below does not work. Here is the code, I appreciate the help:
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    public class simpleTest {
        public static void main(String[] args) throws IOException {
                int rows = 0;
                int count = 0;
                int i = 0;
                String[] wordList = new String[50];
                BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            try {
                Class.forName("com.mysql.jdbc.Driver").newInstance();
            } catch (Exception ex) {System.out.println("No driver");}
         try {
                Connection conn =
              DriverManager.getConnection("jdbc:mysql://localhost/cop4610webs",
              "root", "anatoly");
                // Do something with the Connection
                System.out.println("Enter a string: ");           
                String word = reader.readLine();
                StringTokenizer words = new StringTokenizer(word);
                while(words.hasMoreTokens())
                   wordList[count++] = words.nextToken();
                System.out.println("Enter the logic");
                String logic = reader.readLine();
                Statement stmt = null;
             ResultSet rs = null;
                 stmt = conn.createStatement();
                if(logic.equalsIgnoreCase("exact"))
                 rs = stmt.executeQuery("SELECT pageName FROM pages WHERE pageContent ='"+word+"'");
                 ResultSetMetaData metaData = rs.getMetaData();
                 System.out.println("Results of SELECT");
                rs.last(); //move to last row
                rows = rs.getRow(); //check rows returned
                System.out.println(rows);
                rs.beforeFirst(); //move back to beginning
                if(rows != 0)
                rs.next();
                 System.out.println(rs.getObject(1) );
                while ( rs.next() ) {
                   System.out.println(rs.getObject(1) );
                else
                      if(logic.equalsIgnoreCase("all"))
               while(i < count)
                 rs = stmt.executeQuery("SELECT pageName FROM pages WHERE pageContent ='"+wordList[i]+"'" + "AND" +"'"+wordList[i+1]+"'");
               i++;
                 System.out.println("Results of SELECT");
                rs.last(); //move to last row
                rows = rs.getRow(); //check rows returned
                System.out.println(rows);
                rs.beforeFirst(); //move back to beginning
                if(rows != 0)
                rs.next();
                 System.out.println(rs.getObject(1) );
                while ( rs.next() ) {
                   System.out.println(rs.getObject(1) );
                rs.close();
                 } catch (SQLException ex) { // handle any errors
                System.out.println("SQLException: " + ex.getMessage());
                System.out.println("SQLState: " + ex.getSQLState());
                System.out.println("VendorError: " + ex.getErrorCode());
    }

    rs = stmt.executeQuery("SELECT pageName FROM pages WHERE pageContent ='"+wordList[i]+"'" + "AND" +"'"+wordList[i+1]+"'");should be:
    rs = stmt.executeQuery("SELECT pageName FROM pages WHERE pageContent ='"+wordList[i]+"'" + " AND " +"'"+wordList[i+1]+"'");(spaces around the "and")

  • CANT execute query with parameter on user defined tables using query genera

    Dear All,
    I have problem when executing query with parameter on user defined tables using query generator.
    It seems SBO cannot accept parameter to query user defined tables.
    I've tried these:
    SELECT T0.U_Status FROM [@ST_PR_H] T0 WHERE T0.U_Status = [%0] --- this FAIL
    I try to pass the value directly without using parameter and It works
    SELECT T0.U_Status FROM [@ST_PR_H] T0 WHERE T0.U_Status = 2 --- this SUCCESS
    This one works
    SELECT * FROM RDOC T0 WHERE T0.width =[%0]  --- this SUCCESS
    and this one works too
    SELECT * FROM RDOC T0 WHERE T0.width = 595  --- this SUCCESS
    Is there anyone can help me ....???
    Thanks,
    Alfa

    I  generated this code using query wizard ....
    SELECT T0.[U_Status] AS 'Document Status' FROM  [dbo].[@ST_PR_H] T0  WHERE T0.[U_Status] = (N'2' )
    and replaced the (N'2' ) with [%0]
    SELECT T0.[U_Status] AS 'Document Status' FROM  [dbo].[@ST_PR_H] T0  WHERE T0.[U_Status] = [%0]
    and It worked ......
    Thanks 4 all .....

  • Outer join on query with OR clause

    hi all, i am having problem outerjoining a query with or clause
    here is my data
    WITH table1 AS
    SELECT  'test' txt1, 'pak' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL
    SELECT  null txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL
    SELECT  null txt1, NULL txt2, 'ced3' txt3, 'su3' txt4 FROM dual UNION ALL
    SELECT  null txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL
    SELECT  'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL
    SELECT  null txt1, NULL txt2, null txt3, null txt4 FROM dual
    ,table2 AS
    SELECT 111 pid, 'test' txt1, 'pak4' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL
    SELECT 222 pid, 'test1' txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL
    SELECT 333 pid, 'test2' txt1, 'pak3' txt2, 'ced3' txt3, 'su4' txt4 FROM dual UNION ALL
      SELECT 444 pid, 'test2' txt1, 'pak3' txt2, 'ced4' txt3, 'su3' txt4 FROM dual
    SELECT b.pid, a.*
    from table1 a, table2 b
    WHERE (a.txt1 = b.txt1 OR
           a.txt1 IS NULL AND a.txt2=b.txt2 OR
           Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 = b.txt3 OR
           Nvl(a.txt2, a.txt1) IS NULL  AND a.txt3 IS NULL AND a.txt4 = b.txt4
           ) as you can see i am joining table1 and table 2. i am joining with txt1, if txt1 is null then join by txt2, if null then join by txt3 and so on.
    the code above product this output
    PID     TXT1     TXT2     TXT3     TXT4
    ===     ====     ===   ==== ====
    111     test     pak      ced     su
    222             pak      ced2     su2
    333                     ced3     su3
    444                          su3this output is partially correct. only 4 rows were display and two was left out
    SELECT  'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL
    SELECT  null txt1, NULL txt2, null txt3, null txt4 FROM dual i tried using outer join but oracle complain that i cannot use outerjoin with OR clause.
    can someone help modify my query to display the output below ?
    PID     TXT1     TXT2     TXT3     TXT4
    ===    ====      ===   ====  ====
    111     test     pak      ced     su
    222             pak      ced2     su2
    333                     ced3     su3
    444                          su3
    NULL  NULL   NULL    NULL   NULL
         test5

    Not sure you can do it with the Oracle style outer joins, but wioth ANSI style joins it is simple, actually exactly as you had it.
    SQL> set null null;
    SQL> WITH table1 AS (
      2   SELECT  'test' txt1, 'pak' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL
      3   SELECT  null txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL
      4   SELECT  null txt1, NULL txt2, 'ced3' txt3, 'su3' txt4 FROM dual UNION ALL
      5   SELECT  null txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL
      6   SELECT  'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL
      7   SELECT  null txt1, NULL txt2, null txt3, null txt4 FROM dual),
      8  table2 AS (
      9   SELECT 111 pid, 'test' txt1, 'pak4' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL
    10   SELECT 222 pid, 'test1' txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL
    11   SELECT 333 pid, 'test2' txt1, 'pak3' txt2, 'ced3' txt3, 'su4' txt4 FROM dual UNION ALL
    12   SELECT 444 pid, 'test2' txt1, 'pak3' txt2, 'ced4' txt3, 'su3' txt4 FROM dual)
    13  SELECT b.pid, a.*
    14  from table1 a
    15     LEFT JOIN table2 b
    16        ON (a.txt1 = b.txt1 OR
    17            a.txt1 IS NULL AND a.txt2=b.txt2 OR
    18            Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 = b.txt3 OR
    19            Nvl(a.txt2, a.txt1) IS NULL  AND a.txt3 IS NULL AND a.txt4 = b.txt4);
           PID TXT1   TXT2   TXT3   TXT4
           111 test   pak    ced    su
           222 null   pak    ced2   su2
           333 null   null   ced3   su3
           444 null   null   null   su3
    null       text5  null   null   su3
    null       null   null   null   nullJohn

  • How to use XPath with Namespaces in the xml ?

    Hi all,
    I need to reference a certain Node in a Document using XPath notation.
    The problem is the the XML Document contains Namespaces inside it
    f.e.
    <xn:SubNetwork id="JRANM">
        <xn:VsDataContainer id="1">
           <xn:vsDataType>vsDataAreas</xn:vsDataType>
        </xn:VsDataContainer>
    </xn:SubNetwork >Using DOMXPath (from weblogic.xml.xpath)
      DOMXPath xPath = new DOMXPath("xn:SubNetwork/*");
      Set nodeset = xPath.evaluateAsNodeset(this.xmlRootElement);When I Iterate through the Set I can see it's empty.
    (On the other hand without namespaces everything is fine.)
    So how can I reference a Node that contains a namespace in it ?
    Thanks a lot
    Francesco

    We use the following class to perform XPath Queries on our XmlBean objects.
    Hope this helps,
    Craig
    import java.util.Set;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.apache.xmlbeans.XmlException;
    import org.w3c.dom.Document;
    import weblogic.xml.util.StringInputStream;
    import weblogic.xml.xpath.DOMXPath;
    * Class to encapsulate API specific (i.e. weblogic) XML functions
    public class XmlUtil {
         * Returns a set containing objects of type reflected in the query.<br/>
         * e.g.<br/>
         * /saur:tree/saur:treeNode[@label='My Reports']<br/>
         * Returns a Set of TreeNode objects<br/>
         * Sample Code: <br/>
         * <code>
         * Set set = XmlUtil.executeXPathQuery( myQuery, tree.xmlText());
         * for( Iterator iter = set.iterator(); iter.hasNext();) {
         *     TreeNode node = TreeNode.Factory.parse((Node)iter.next());
         *     // Do whatever...
         * </code>
         * @param query
         * @param xml
         * @return
        public static Set executeXPathSetQuery( String query, String xml) throws XmlException {
            try {
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();   
                factory.setNamespaceAware(true);
                DocumentBuilder builder = factory.newDocumentBuilder();
                StringInputStream in = new StringInputStream(xml);
                Document doc = builder.parse(in);
                DOMXPath xQuery =  new DOMXPath(query);
                return xQuery.evaluateAsNodeset(doc);
            catch(Exception x) {
                throw new XmlException("Error running XPath query", x);
    }

  • XPath expression with multiple namespaces?

    Hello all.
    I have been scouring the forums and Google and can't seem to find anything similar to my problem.
    I have the following XML with three namespaces. Two are defined in the root element and the third is defined in the the IdSession element. To make things even more confusing, the second and third namespaces have the same prefix, 'f'.
    This is the xml:
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <NamespaceTestCall xmlns="http://my.default/namespace"
    xmlns:f="http://my.second/namespace">
    ...<f:Level1>
    ......<f:IdSession xmlns:f="http://my.third/namespace">12345</f:IdSession>
    ......<Language>ENG</Language>
    ...</f:Nivel1>
    </NamespaceTestCall>
    My question is, how do I get at the IdSession element? Don't I need to create an XPath object and assign it more than one NamespaceContext?
    This is what I am doing:
    Document xmlDocument = loadXML(xmlSource);
    XPath xpathEvaluator = XPathFactory.newInstance().newXPath();
    xpathEvaluator.setNamespaceContext(new NamespaceContextProvider("a", "http://my.third/namespace"));
    ... xpathEvaluator.evaluate("//a:IdSession", ...);
    This code works but it might not return the 'IdSession' I want, since by searching like this '//a:IdSession' it is looking in the whole document. If there were another 'IdSession' somewhere else in the document with the same URI, it would be returned. I want the 'IdSession' that lives inside of 'Level1'.
    So what I would like to do is something like this:
    ... xpathEvaluator.evaluate("/*/Level1/a:IdSession", ...);
    But this does NOT work because 'Level1' has its own namespace. So what it seems like I need to do is the following:
    ... xpathEvaluator.evaluate("/*/b:Level1/a:IdSession", ...);
    Having already added the 'Level1' namespace to the XPath object, with the prefix 'b'. But unlike JDOM, there is no 'add' functionality, only 'set', meaning if you call set twice the second call overwrites the first.
    Is there anyway to do this?
    Many thanks!
    Bob

    Hello,
    Sorry, that was my bad. I should have explained that NamespaceContextProvider is nothing more than my implementation of the NamespaceContext interface. The way I did it, I simply implemented getNamespaceURI() and getPrefix(). And the constructor accepted two parameters -- prefix and URI. So my problem was that when I assigned this NamespaceContext to my XPath object it would only have one prefix and one URI.
    But I found an implementation here:
    http://www.oreillynet.com/cs/user/view/cs_msg/50304
    that instead of only having one prefix and URI uses a map. Thus its method setNamespace() adds the prefix and URi to the map, and getPrefix() and getPrefixes() retrieve them from the map.
    Now when I want to use more than one namespace I simply call setNamespace() as many times as necessary, adding a prefix and URI pair each time, and when I am done I assign it to my XPath object.
    And it works!
    Thanks for the response!
    Bob

  • Why XPath didnot work with Namespace ?

    Dear all,
    When I parsing a xml document with Namespace by XPath , it didnot work well , but if I remove the part of Namespace , it worked well , I am not sure if I processed with right steps , any help is appreciated :
    My parser : jdom-b9
    jdk : 1.4.1
    My code is like :
    import java.io.*;
    import java.util.*;
    import org.jdom.*;
    import org.jdom.input.*;
    import org.jdom.output.*;
    import org.jdom.xpath.*;
    public class XPathTest {   
        public static void main(String[] args) throws IOException, JDOMException {
            if (args.length != 1) {
                System.err.println("Usage: samples.XPathTest [test.xml]");
                return;
            String filename = args[0];
            PrintStream out = System.out;
            SAXBuilder builder = new SAXBuilder();
            Document doc = builder.build(new File(filename));
            Element root = doc.getRootElement();          
            XPath path = XPath.newInstance("//Worksheet");          
            path.addNamespace("ss","urn:schemas-microsoft-com:office:spreadsheet");
            // or use :
            //Namespace ns = root.getNamespace();
            //path.addNamespace(ns);
            List elementNames = path.selectNodes(doc);
            if (elementNames.size() == 0) {
                out.println("This xml contains no element <Worksheet>");
            } else {
                out.println("This xml contains " + elementNames.size() + " <Worksheet> :");
                Iterator i = elementNames.iterator();
                while (i.hasNext()) {
                    out.println("\t" + ((Element)i.next()).getName());
    }and test.xml :
    <?xml version="1.0"?>
    <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
    xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:html="http://www.w3.org/TR/REC-html40">
    <Worksheet ss:Name="Sheet2">
      <Table ss:ExpandedColumnCount="12" ss:ExpandedRowCount="38" x:FullColumns="1"
       x:FullRows="1" ss:DefaultColumnWidth="54" ss:DefaultRowHeight="14.25">
       <Column ss:Width="63"/>
       <Column ss:Width="76.5"/>
       <Column ss:Width="103.5"/>
       <Column ss:Width="123"/>
       <Column ss:Width="136.5"/>
       <Column ss:Width="83.25"/>
       <Column ss:Width="39"/>
       <Column ss:Width="76.5"/>
       <Column ss:Width="103.5"/>
       <Column ss:Width="90"/>
       <Column ss:Width="76.5"/>
       <Column ss:Width="90"/>
       <Row>
        <Cell><Data ss:Type="String">PORT_CODE</Data></Cell>
        <Cell><Data ss:Type="String">EFFECT_DATE</Data></Cell>
        <Cell><Data ss:Type="String">END_DATE</Data></Cell>
        <Cell><Data ss:Type="String">ENCODE_SCHEME_PORT</Data></Cell>
        <Cell><Data ss:Type="String">PORT_NAME</Data></Cell>
        <Cell><Data ss:Type="String">COUNTRY_CODE</Data></Cell>
        <Cell><Data ss:Type="String">IS_RT</Data></Cell>
        <Cell><Data ss:Type="String">DATA_SOURCE</Data></Cell>
        <Cell><Data ss:Type="String">LAST_UPD_DATE</Data></Cell>
        <Cell><Data ss:Type="String">LAST_UPD_USER</Data></Cell>
        <Cell><Data ss:Type="String">BP_UPD_DATE</Data></Cell>
        <Cell><Data ss:Type="String">PROVINCE_CODE</Data></Cell>
       </Row>
      </Table>
    </Worksheet>
    </Workbook>test1.xml
    <?xml version="1.0"?>
    <Workbook>
    <Worksheet Name="Sheet2">
      <Table>
       <Column Width="63"/>
       <Column Width="76.5"/>
       <Column Width="103.5"/>
       <Column Width="123"/>
       <Column Width="136.5"/>
       <Column Width="83.25"/>
       <Column Width="39"/>
       <Column Width="76.5"/>
       <Column Width="103.5"/>
       <Column Width="90"/>
       <Column Width="76.5"/>
       <Column Width="90"/>
       <Row>
        <Cell><Data Type="String">PORT_CODE</Data></Cell>
        <Cell><Data Type="String">EFFECT_DATE</Data></Cell>
        <Cell><Data Type="String">END_DATE</Data></Cell>
        <Cell><Data Type="String">ENCODE_SCHEME_PORT</Data></Cell>
        <Cell><Data Type="String">PORT_NAME</Data></Cell>
        <Cell><Data Type="String">COUNTRY_CODE</Data></Cell>
        <Cell><Data Type="String">IS_RT</Data></Cell>
        <Cell><Data Type="String">DATA_SOURCE</Data></Cell>
        <Cell><Data Type="String">LAST_UPD_DATE</Data></Cell>
        <Cell><Data Type="String">LAST_UPD_USER</Data></Cell>
        <Cell><Data Type="String">BP_UPD_DATE</Data></Cell>
        <Cell><Data Type="String">PROVINCE_CODE</Data></Cell>
       </Row>
      </Table>
    </Worksheet>
    </Workbook>The output of test.xml is : This xml contains no element <Worksheet>
    The output of test1.xml with no namespace part is :
    This xml contains 1 <Worksheet> :
    Worksheet
    WHY ????????????????????????????

    I do not use jdom but I had similar problems. You can try "//:worksheet". The prefix for the default namespace might be "". it fixed my problem.
    wz

  • Xpath query return problem

    Hi;
    I want to load xml file into the database oracle 9.0.2 using Oracle XML DB Utilities Package on "http://otn.oracle.com/sample_code/tech/xml/xmldb/xdbutilities/XMLDB_Utilities_Overview.htm"
    I have a schema like:
    <xs:element name="catalog">
    <xs:element name="catalog">
    <xs:complexType xdb:SQLType="OBJ_CATALOG">
    <xs:sequence>
    <xs:element name="category">
    <xs:complexType xdb:SQLType="OBJ_CATEGORY">
    <xs:sequence>
    <xs:element name="product">
    <xs:complexType xdb:SQLType="OBJ_PRODUCT">
    <xs:sequence>
    <xs:element name="name" type="xs:string"/>           
    and my file include:
    [i]<catalog>
    <category name="books">
    <product id="1" keywords="yasanti, Latin Amerika" >
    <name>Gunes Topraklari</name>
    </product>
    </category>
    <category name="CDs" >
    <product id="5" keywords="music, easy listening" >
    </product>
    </category>
    I can use xpath query like
    select extract(value(x), '/catalog/category[@name="books"]').getstringval() from product_table x
    and get result but I can not take any data about product elements with queries such that
    select extract(value(x), '/catalog/category[@name="books"]//name/text()').getstringval() from product_table x
    Does anyone has an idea about this problem?
    Thanks a lot.
    Alper.

    Please post this message at:
    Forums Home » Oracle Technology Network (OTN) » Products » Database » XML DB

Maybe you are looking for

  • No 3G signal after 4.0.2 upgrade on iPhone 4 O2 UK

    Has any one else had this problem? I had a very strong 3G signal before I upgraded to 4.0.2. Now I only have storng Edge signal or strong GPRS signal. I have phoned O2 and they have told me that there is no problem with their Network. On the advice o

  • How can I get my iphone to synch with Outlook?  I do not want to use Icloud.

    I am a realtor and have used Outlook for years, but am unable to get my iphone to synch with Outlook.  Does anyone have a solution?  I have been to the Apple store and have had more than one person working on it, to no avail.

  • Roles Tab is missing in authorizations :(

    Hi , I am not able to assign Role GW_Admin and GW_User as in the authorizations Content, i do not see roles Tab. Please help how to add above roles to i067753trial user.

  • Authentication Scheme with Username / Password stored in App Table

    Hi all, Up to now all of our applications have used SSO authentication, but I now need to step away from this to allow users from outside our organisation (and therefore not in our OID system) to use one specific application. I therefore have a table

  • Adobe Forms On Portal

    Hi Experts, My requirement is i need to create the interactive adobe form and this adobe form is finally accessed through portal and there are some approval process involved in this scenario. Now my doubt is do i need to create the adobe form through