Equivalent of SQL JOINs using XML + XPath

I have been working on a Java app for a while that takes user queries and searches various translations of the Bible. The data is stored in 66 .xml files, one per book of the Bible, and those files, in turn, are stored in a .jar file.
The user may select 2 or more translations and see them in parallel. So for example, let's say that want Matthew chapter 1 and verses 1 to 10 from KJV and ASV. I simply use the following XPath expression: /book/chapter[@num=1]/verse[@num>=1 and @num<=10] . Then I use XPathFactory, XPath, compile() and evaluate() on Matthew.xml from kjv.jar and asv.jar.
However, the problem is not so simple for keyword queries from the user. In such a case the tool searches for keywords in one translation and then finds the same verses from all subsequent translations. Here the XPath expression might be more like: /book/chapter/verse[contains(., 'keyword1') and contains(., 'keyword2')] for the first translation. However, if I ran the same query on subsequent translations they may or may not return the exact same set of verses (depending on language (English, Greek, Hebrew) and also on the dialect (Old English vs. Modern English)). So, my question is what is the most efficient way of obtaining the same verses from subsequent translations?
I could simply look up the verses in the first translation, then use DOM API calls to find the chapter and verse numbers, and look those up in the other translations. But this seems tedious, SLOW, and possibly more error prone.
Also, a second question: if I wanted to include a help file in my application's .jar file. How could I access that file programmatically? That is, how do I tell the application to look for "help.html" in the jar file so I can manipulate and/or display the contents to the user?
And last question: since, I'm still learning my way around Java and XML, how would I go about programmatically applying a .xsl file to some given .xml input to produce HTML + CSS output? What classes, interfaces, etc. should I look up for this? And can anyone point me to sample code online for this?

However, the problem is not so simple for keyword
queries from the user. In such a case the tool
searches for keywords in one translation and then
finds the same verses from all subsequent
translations. Here the XPath expression might be
more like: /book/chapter/verse[contains(.,
'keyword1') and contains(., 'keyword2')] for the
first translation. However, if I ran the same query
on subsequent translations they may or may not return
the exact same set of verses (depending on language
(English, Greek, Hebrew) and also on the dialect (Old
English vs. Modern English)). So, my question is
what is the most efficient way of obtaining the same
verses from subsequent translations?
I could simply look up the verses in the first
translation, then use DOM API calls to find the
chapter and verse numbers, and look those up in the
other translations. But this seems tedious, SLOW,
and possibly more error prone.There's nothing in XPath that I know of that helps with this. SQL is relational, XML is hierarchical. They're fundamentally different.
Also, a second question: if I wanted to include a
help file in my application's .jar file. How could I
access that file programmatically? That is, how do I
tell the application to look for "help.html" in the
jar file so I can manipulate and/or display the
contents to the user?If it's an HTML file, it's likely that you'll package it in a WAR file, along with the rest of your app. It's accessible as a URL that way.
And last question: since, I'm still learning my way
around Java and XML, how would I go about
programmatically applying a .xsl file to some given
.xml input to produce HTML + CSS output? What
classes, interfaces, etc. should I look up for this?.xsl transformations are applied using XSL-T engines, like Apache's Xalan. You would embed the HTML that you want to inject the XML data into in the XSL-T stylesheet.
That's one way. Another is to use a templating alternative like Velocity.
And can anyone point me to sample code online for this?Try the Apache Xalan docs. Or this:
http://www.cafeconleche.org/books/xmljava/chapters/ch17.html
%

Similar Messages

  • How to use XML / XPath in JAVA (in 1.4) which third part component to use?

    How to use XML / XPath in JAVA (in 1.4)
    I'm absolutely novice in XML
    but I need to query XML using XPath
    As I understand XPath become avalible only in Java 1.5
    But I use 1.4 (project requirement)
    Which third part component could you recomend?

    Can anyone help me with this XPath query
    I get result [title: null]
    import java.io.*;
    import javax.xml.parsers.*;
    import org.xml.sax.*;
    import org.w3c.dom.*;
    import org.jaxen.*;
    import org.jaxen.dom.*;
    import org.jaxen.saxpath.*;
    import java.util.*;
    public class TestX {
         public void ggg() {
              try {
                   File f = new File("journal.xml");
                   DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                   org.w3c.dom.Document doc = docBuilder.parse(f);
                   XPath xpath = new DOMXPath( "/journal/article/title" );
                   List result = (List) xpath.evaluate(doc);
                   System.out.println(result.get(0));
              } catch (Exception e) {
                       e.printStackTrace();
         public static void main(String[] args) {
              TestX tx = new TestX();
              tx.ggg();
    }journal.xml
    <journal>
        <article id="article.1">
            <title>Art1</title>
            <author>
               <first>Bob</first>
               <last>McWhirter</last>
            </author>
            <text>
            </text>
        </article>
        <article id="article.2">
            <title>Art2</title>
            <author>
               <first>James</first>
               <last>Strachan</last>
            </author>
            <text>
            </text>
        </article>
    </journal>

  • SQL - JOIN using UNION ?? UNION using JOIN ?? with example!

    I was asked this question during one of my interviews. Can you do JOIN using UNION keyword? Can you do UNION using JOIN keyword?
    That is -
    1. I should get same output as JOIN without using JOIN keyword, but using UNION Keyword?
    2. I should get same output as UNION without using UNION keyword, but using JOIN Keyword?
    Can you give me an example of how to do this if possible?

    Hi,
    Welcome to the forum!
    user13067794 wrote:
    I was asked this question during one of my interviews. Can you do JOIN using UNION keyword? Can you do UNION using JOIN keyword?The correct answer to those questions is: Why would you want to? All versions of Oracle (and probably any other database product) provide JOIN to do certain things and UNION to do other things. Why not use those features the way they were designed to be used? Even if it is possible to do what you ask, it's going to be more complicated and less efficient.
    If you really must:
    That is -
    1. I should get same output as JOIN without using JOIN keyword, but using UNION Keyword? You can select the relevant columns from each table, and NULLs for all the columns from other tables, in a UNION query. Then you can use GROUP BY or analytic functions to combine data from different rows. For example, this JOIN:
    SELECT     d.dname
    ,     e.mgr
    FROM     scott.dept     d
    JOIN     scott.emp     e  ON     d.deptno  = e.deptno
    ;could be written using UNION, but no JOIN, like this:
    WITH     union_data     AS
         SELECT     deptno
         ,     dname
         ,     NULL     AS empno
         ,     NULL     AS mgr
         FROM     scott.dept
        UNION ALL
         SELECT     deptno
         ,     NULL     AS dname
         ,     empno
         ,     mgr
         FROM     scott.emp
    ,     quasi_join     AS
         SELECT     MAX (dname) OVER (PARTITION BY deptno)     AS dname
         ,     mgr
         ,     empno
         FROM     union_data
    SELECT     dname
    ,     mgr
    FROM     quasi_join
    WHERE     empno     IS NOT NULL
    ;Depending on your tables and your requirements, you might be able to do something a little simpler.
    2. I should get same output as UNION without using UNION keyword, but using JOIN Keyword?A FULL OUTER JOIN is similar to UNION.
    This UNION query:
    SELECT     dname          AS txt
    FROM     scott.dept
    UNION
    SELECT     TO_CHAR (mgr)     AS txt
    FROM     scott.emp
    ;Can be written like this, using JOIN but no UNION:
    SELECT DISTINCT
         NVL2 ( e.empno
              , TO_CHAR (e.mgr)
              , d.dname
              )          AS txt
    FROM          scott.dept     d
    FULL OUTER JOIN     scott.emp     e  ON       1 = 2
    user13067794 wrote:I too don't any example as such, but I am thinking on this line -
    Select a.x, b.y
    from a,b
    where a.key=b.key and sal<5000
    UNION
    Select a.x, b.y
    From a,b
    Where a.key=b.key and sal>7000
    can we get same result using JOIN?That's a very special case. You can get the same results without using UNION like this:
    Select distinct
         a.x
    ,      b.y
    from      a
    ,     b
    where      a.key     = b.key
    and      (        sal < 5000
         OR     sal > 7000
    Can we do something similar using UNION without using JOIN keyword??What you posted does not use the JOIN keyword.
    To get the same results without using a join (either with or without the JOIN keyword), you can use UNION together with aggregate or analytic functions, as I showed earlier.
    Edited by: Frank Kulash on Jul 5, 2011 9:01 PM

  • Can you use Object Relational SQL to access XML content ?

    Is there a possibility to use the generated object types and collection types to conveniently access the xml data?

    Technically there is nothing to prevent you from using the object types generared when an XML Schema is registered to access and manipulate the contents of the instance documents that conform to the Schema. This would be done using the notation x.xmldata.attribute In this case x would be the object table, xmldata is the name of the instance of the SQL object type associated with the table in question.
    However we do not encourage or recommend this approach. Currently XML DB provides the application developer with DML / DDL independence. This holds true as long as you use XPATH expressions to express your DML operations. Using XPATH expressions to access the content of an XML document maintains an abstraction between the DML (XPATH) and the underlying Object Relational Storage Structure derived from the information in the corresponding XML Schema. Whereever possible, when you express a query using an XPATH expression, under the covers we attempt to re-write the query into Object Relational SQL, based on the meta data contained in the Schema, as access v
    If you use the object notation to access the content of the document you break this abstraction. Your application now needs to be aware of the physical (object relational) storage model being used to manage the instance documents.
    One of the key features of XML DB is that it allow a developer to use Schema Annotations to alter the storage model used to manage the instance documents. The most common example of this is using annotations to control the way in which collections are managed. Depending on the annotation in the schema you can store collections as a VARRAY, as a NestedTable or as a separate XMLType table. Dependong on the technique chosed the objects that are generated during the XML Schema registration process will change.
    If you use the XPATH expressions to accesss the content of your documents, and you decided to change the annotations in your schema so as to revise the way your documents are stored, XML DB will ensure your code should continue to work unchanged, regardless of which objects are generated during Schema registration. On the other hand, if you use the object notation to access the content of the documents, and then change the annotation you will have to change your code.
    I hope this clarifies the situation..

  • Can we use xml Publisher reporting for sql* Plus in EBS

    Hello All,
    The current report is designed in Sql* Plus Executable report and the output is in txt format, Now the requirement is to have the output in Excel format.
    So is it possible to use the xml reporting and make the output as Excel from the word template we design from MSword as we do for rdf(I have done few reports created in rdf to xml publisher reports in EBS and stand alone as well.).
    Do the same procedure will suit for Sql*Plus reports tooo or Is there any work around to achieve this.
    Thanks and Regards
    Balaji.

    Hi
    Thanks for the reply..
    I tried to do the follwoing
    1. changed the output to xml in the conc. prog.
    2. ran the same report but i am getting the follwoing error in the output file
    The XML page cannot be displayed
    Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
    Invalid at the top level of the document. Error processing resource
    Other reports which are using the Oracle Reports(rdf) as source, i am able to generated the xml as expected....
    So my question is whether we can use sql* reports executable and generate xml in the conc.prog.
    if any one has used the sql*reports for xml publisher reporting... please let me know, so that if its possible i will check my sql needs some validation or tuning...
    thanks in advance
    Balaji.

  • [Forum FAQ] How do i use xml stored in database as dataset in SQL Server Reporting Services?

    Introduction
    There is a scenario that users want to create SSRS report, the xml used to retrieve data for the report is stored in table of database. Since the data source is not of XML type, when we create data source for the report, we could not select XML as Data Source
    type. Is there a way that we can create a dataset that is based on data of XML type, and retrieve report data from the dataset?
    Solution
    In this article, I will demonstrate how to use xml stored in database as dataset in SSRS reports.
    Supposing the original xml stored in database is like below:
    <Customers>
    <Customer ID="11">
    <FirstName>Bobby</FirstName>
    <LastName>Moore</LastName>
    </Customer>
    <Customer ID="20">
    <FirstName>Crystal</FirstName>
    <LastName>Hu</LastName>
    </Customer>
    </Customers>
    Now we can create an SSRS report and use the data of xml type as dataset by following steps:
    In database, create a stored procedure to retrieve the data for the report in SQL Server Management Studio (SSMS) with the following query:
    CREATE PROCEDURE xml_report
    AS
    DECLARE @xmlDoc XML;  
    SELECT @xmlDoc = xmlVal FROM xmlTbl WHERE id=1;
    SELECT T.c.value('(@ID)','int') AS ID,     
    T.c.value('(FirstName[1])','varchar(99)') AS firstName,     
    T.c.value('(LastName[1])','varchar(99)') AS lastName
    FROM   
    @xmlDoc.nodes('/Customers/Customer') T(c)
    GO
    P.S. This is an example for a given structured XML, to retrieve node values from different structured XMLs, you can reference here.
    Click Start, point to All Programs, point to Microsoft SQL Server, and then click Business Intelligence Development Studio (BIDS) OR SQL Server Data Tools (SSDT). If this is the first time we have opened SQL Server Data Tools, click Business Intelligence
    Settings for the default environment settings.
    On the File menu, point to New, and then click Project.
    In the Project Types list, click Business Intelligence Projects.
    In the Templates list, click Report Server Project.
    In Name, type project name. 
    Click OK to create the project. 
    In Solution Explorer, right-click Reports, point to Add, and click New Item.
    In the Add New Item dialog box, under Templates, click Report.
    In Name, type report name and then click Add.
    In the Report Data pane, right-click Data Sources and click Add Data Source.
    For an embedded data source, verify that Embedded connection is selected. From the Type drop-down list, select a data source type; for example, Microsoft SQL Server or OLE DB. Type the connection string directly or click Edit to open the Connection Properties
    dialog box and select Server name and database name from the drop down list.
    For a shared data source, verify that Use shared data source reference is selected, then select a data source from the drop down list.
    Right-click DataSets and click Add Dataset, type a name for the dataset or accept the default name, then check Use a dataset embedded in my report. Select the name of an existing Data source from drop down list. Set Query type to StoredProcedure, then select
    xml_report from drop down list.
    In the Toolbox, click Table, and then click on the design surface.
    In the Report Data pane, expand the dataset we created above to display the fields.
    Drag the fields from the dataset to the cells of the table.
    Applies to
    Reporting Services 2008
    Reporting Services 2008 R2
    Reporting Services 2012
    Reporting Services 2014
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    I have near about 30 matrics. so I need a paging. I did every thing as per this post and it really works for me.
    I have total four columns. On one page it should show three and the remaining one will be moved to next page.
    Problem occurs when in my first row i have 3 columns and in next page if I have one columns then it show proper on first page but on second page also it gives me three columns insted of one. the first column data is exactly what I have but in remaining two
    columns it shows some garbage data.
    I have data like below.
    Metric ColumnNo RowNo
    1 1
    1
    2 2
    1
    3 3
    1
    4 1
    2
    so while grouping i have a row parent group on RowNo and Column group on ColumnNo.
    can anyone please advice on this.

  • Generating multi-level XML in Oracle 8i using XML-SQL utility

    Oracle 8i has a limitation when it comes to the object types. Only one-level nesting of collection is allowed. Oracle 9i apparently removes this limitation.
    I am trying to generate XML for a hierarchical (conceptually) structure. To do that I am using XML-SQL utility (XSU) running agains an object view build on top of the relational data. The problem is the limit to onelevels of colelction nesting. Oracle 8i gives you a way to create a view with more levels of nesting by using references (REF). The problem is that when XSU runs agains a view with the references, it inserts the references into the XML document (instead of dereferencing them).
    Is there a way to generate XML with Oracle 8i with more than two levels of collection nesting?
    Thank you.
    Michael

    Oracle 8i has a limitation when it comes to the object types. Only one-level nesting of collection is allowed. Oracle 9i apparently removes this limitation.
    I am trying to generate XML for a hierarchical (conceptually) structure. To do that I am using XML-SQL utility (XSU) running agains an object view build on top of the relational data. The problem is the limit to onelevels of colelction nesting. Oracle 8i gives you a way to create a view with more levels of nesting by using references (REF). The problem is that when XSU runs agains a view with the references, it inserts the references into the XML document (instead of dereferencing them).
    Is there a way to generate XML with Oracle 8i with more than two levels of collection nesting?
    Thank you.
    Michael

  • About SQL Query using joins

    Hi,
    I want to write a SQL statement using Joins. The base table "A" has about 100 fields and the join table "B" a few. I would like to fetch all fields from table "A" and a few from table "B".
    Is there a way to write a query wherein I can use "Select * " for table "A" rather than writing all 100 field name in the query? Please keep in mind that I want to use a Join.
    Thanks.

    Hi Thomas,
    but if there are some fields which are in both tables, SELECT * will be not sufficient. E.g. fields ERNAM, ERDAT, AENAM, AEDAT are such fields which can occur in more tables. In case that a target area will contain these fields, by * with addition INTO CORRESPONDING FIELDS OF, you are not able to specify from which table these values should be taken. In such case, it can be solved by specifying field list dynamically. If it is not that case SELECT * is sufficient. You should check intersection of common fields for tables you are joining. Thereafter you should decide if you can use SELECT *.
    Maybe for better understanding, what exactly I am talking about, look at this example:
    TYPES: BEGIN OF ts_data,
            ernam TYPE mara-ernam,
           END OF ts_data.
    DATA: ls_data TYPE ts_data,
          ls_mara TYPE mara,
          ls_mchb TYPE mchb.
    START-OF-SELECTION.
      ls_mara-matnr = '1'.
      ls_mchb-matnr = ls_mara-matnr.
      ls_mara-ernam = 'A'.
      ls_mchb-ernam = 'B'.
      INSERT mara FROM ls_mara.
      INSERT mchb FROM ls_mchb.
      SELECT SINGLE * FROM mara INNER JOIN mchb ON mara~matnr = mchb~matnr INTO CORRESPONDING FIELDS OF ls_data.
      ROLLBACK WORK.
    You as a developer are not able to tell from which table common fields should be selected. But maybe this is really too specific case...
    Regards,
    Adrian

  • XML Signature using an XPath filter

    I want to sign an XML document, just based on the content of a particular element in the document. Based on the jwsdp docs it looked pretty simple, but I'm getting strange results. I'll get the same digest value in the SignedInfo for different Xpath filter strings.
    Anybody out there have good luck trying to sign XML documents using Xpath filters?
    I'm using JDK 1.5.05 and JWSDP 1.6.
    Here is my simple XML doc
    <?xml version="1.0" encoding="UTF-8"?>
    <myns:whole_doc xmlns:myns="http://namespace.myns.com/test"
    attr1="attr_one" attr2="attr_two" attr3="attr_three">
    <myns:part_one attr="attr_one">
    <myns:tag1>this is part_one tag_one</myns:tag1>
    <myns:tag2>this is part_one tag_two</myns:tag2>
    </myns:part_one>
    <myns:part_two attr="attr_two">
    <myns:tag1>this is part_two tag_one</myns:tag1>
    <myns:tag2>this is part_two tag_two</myns:tag2>
    </myns:part_two>
    <myns:part_three attr="attr_three">
    <myns:tag1>this is part_three tag_one</myns:tag1>
    <myns:tag2>this is part_three tag_two</myns:tag2>
    </myns:part_three>
    </myns:whole_doc>
    When I use an XPath filter = "/myns:whole_doc/myns:part_one" I get the same digest as when I use "/myns:whole_doc/myns:part_two", which is the same digest when I don't use XPath filtering. See example output below
    <?xml version="1.0" encoding="UTF-8" ?>
    - <myns:whole_doc xmlns:myns="http://namespace.myns.com/test" attr1="attr_one" attr2="attr_two" attr3="attr_three">
    - <myns:part_one attr="attr_one">
    </myns:part_three>
    - <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
    - <SignedInfo>
    <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments" />
    <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#dsa-sha1" />
    - <Reference URI="">
    - <Transforms>
    <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
    - <Transform Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116">
    <XPath>/myns:whole_doc/myns:part_two</XPath>
    </Transform>
    </Transforms>
    <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
    <DigestValue>9D5CFDkWd9bHx65txuHOeXWeTns=</DigestValue>
    </Reference>
    </SignedInfo>
    <SignatureValue>D686H//H5A0zDrlQx8+0fBNpVeJGgWdTXivlI8S/+WqB/E4oBYzeIQ==</SignatureValue>
    </Signature>
    </myns:whole_doc>

    It took me all day, but I did find the answer.
    When using XPath filters in references, you can't use XPath exactly the way you would use XPath to find nodes in a document. I can't exactly explain why, but it has to do with the fact that the XPath statement is acting as a filter.
    Anyway, to just include the part_one element from the following abbreviated XML
    <myns:whole_doc> .....
    <myns:part_one> ..... </myns:part_one>
    <myns:part_two> .... </myns:part_two>
    </myns:whole_doc>
    the XPath statement should be "ancestor-or-self::myns:part_one"
    to make sure that part_one was part of whole_doc you could use something like
    (ancestor-or-self::node() = /myns:whole_doc/myns:part_one)
    This allows me to sign a document, but still allow portions outside of whole_doc/part_one to change.

  • XML to SQL conversion using OracleXML putXML

    Hi,
    How many rowTag values can I use when I use OracleXML putXML ? I have an XML file in the following format.
    I have to use "ABC" as rowTag. What Can I do with "GRANT_ROW" ? I have a table with
    R_DATE and
    GRANT columns
    where GRANT is an object type with elements
    NAME and ATYPE.
    Thanks.
    <?xml version = '1.0'?>
    <EXCH>
    <ABC num="1">
    <R_DATE>5/21/2003 0:0:0</R_DATE>
    <GRANT>
    <GRANT_ROW num="1">
    <NAME>GUNACAR</NAME>
    <ATYPE>TE</ATYPE>
    </GRANT_ROW>
    <GRANT_ROW num="2">
    <NAME>GUNACAR</NAME>
    <TYPE>TE</TYPE>
    </GRANT_ROW>
    </GRANT>
    </ABC>
    </EXCH>
    I get the following error when I run
    java OracleXML putXML ....
    oracle.xml.sql.OracleXMLSQLException: 'The XML element tag 'GRANT_ROW'
    does not match the name of any of the columns/attributes of the
    target database object.' encountered during processing ROW element 0.
    Thanks....

    RTF FormattingKit
    http://www.schema.de/sitehtml/site-e/xmlnach0.htm

  • Oracle equivalent of SQL Server's "FOR XML" and "OPENXML"

    Hi
    Can someone please tell what are the Oracle's equivalent of SQL Server's "FOR XML" and "OPENXML" features?

    Probably you can try General XML forum General XML
    Gints Plivna
    http://www.gplivna.eu

  • I have to use XML in PL/SQL

    Hi all,
    I would like to know how to use XML in PL/sql. I would like to know how to go about it. I have installed Oracle 9i and what should I do next. I could not find any step by step documentation.
    Please any help is appreciated.
    Thanks
    Kalpana.K

    The following documentation on Oracle XML DB would be useful:
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96620/toc.htm
    And this one about Oracle XDK for PL/SQL:
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96621/partpg5.htm#435787

  • How to extract a tagged string using XML in sql server 2014?

    A column stores the string data with tag as below.I have to retrieve the value of ATRB_C1 as val1234 through xml
    Query:
    CREATE TABLE #test (col varchar(500))
    INSERT INTO #test VALUES('< ATRB_C value ="val1" />< ATRB_C1 value ="val234" />')
    SELECT * FROM  #test FOR XML RAW
    Output:
    <row col="&lt; ATRB_C value =&quot;val1&quot; /&gt;&lt; ATRB_C1 value =&quot;val234&quot; /&gt;" />
    Since the format is incorrect, not able to extract using xml.value
    Any help would be appreciated!!

    CREATE TABLE #test (col xml)
    INSERT INTO #test(col) VALUES('<ATRB_C value ="val1"/><ATRB_C1 value ="val234" />')
    SELECT * FROM #test
    Select Col1.value('(@value)[1]','varchar(20)') as [tab1_col1],col2.value('(@value)[1]','varchar(20)') as [tab2_col2]
    from #test cross apply col.nodes('/ATRB_C') as tab1(col1)
    cross apply col.nodes('/ATRB_C1') as tab2(col2)
    drop table #test
    Hope it Helps!!

  • Sql:variable and XML query performance

    Can someone help with sql:variable() in xml queries?  It seems that when I attempt to reference variables with the sql:variable(...) function in an xpath function (exist or nodes) it comes up with a totally different query plan, possibly ignoring
    my secondary indices like the ones for VALUE, PATH.
    But if I replace sql:variable("@p_ObjectIdentifierForReference") with the literal (ie. "ord/p/ord0616.p") then it uses secondary indices more consistently.
    Below you will see an unsuccessful attempt to get the query to "OPTIMIZE FOR" a specific literal value of @p_ObjectIdentifierForReference.  But this doesn't give work.  It doesn't give me a plan using the secondary index I expect.
    Ideally there would be a way to get the sql:variable(...) function to give the same query plan as a literal. Not sure why that isn't the default behavior.
    DECLARE
    @p_ObjectIdentifierForReference
    varchar(500);
    SET
    @p_ObjectIdentifierForReference
    = 'ord/p/ord0616.p';
    WITH
    XMLNAMESPACES ('uri:schemas-progress-com:XREFD:0004'
    as D)
    SELECT  
    XREF_FileDataReference.XREF_FileData     
    AS XrefFileData,
    InnerRowNode.value('/D:Reference[1]/D:File-num[1]',
    'int') 
    AS FileNumber,
    InnerRowNode.value('/D:Reference[1]/D:Line-num[1]',
    'int') 
    AS LineNumber
    FROM
    (SELECT
    XREF.XREF_FileData.XREF_FileData,
    XREF.XREF_FileData.XREF_FileEntry,
    InnerRow.query('.')
    AS InnerRowNode
     FROM
    XREF.XREF_FileData
    OUTER APPLY
    DataXref.nodes('/D:Cross-reference/D:Source/D:Reference[@Object-identifier = sql:variable("@p_ObjectIdentifierForReference")
    and @Reference-type = "RUN"]')
    as T(InnerRow)                                                           
    WHERE    DataXref.exist('/D:Cross-reference/D:Source/D:Reference[@Object-identifier
    = sql:variable("@p_ObjectIdentifierForReference") and @Reference-type = "RUN"]')
    = 1) 
    AS XREF_FileDataReference
     INNER
    JOIN  XREF.XREF_MemberBuilt  
    ON XREF_MemberBuilt.XREF_FileData  
    = XREF_FileDataReference.XREF_FileData
     INNER
    JOIN  XREF.XREF_FileEntry 
    ON XREF_FileEntry.XREF_FileEntry
    = XREF_FileDataReference.XREF_FileEntry 
    WHERE
    XREF_MemberBuilt.XREF_ProjectBuilt
    = 69
    OPTION(RECOMPILE,
    OPTIMIZE FOR (@p_ObjectIdentifierForReference
    = 'ord/p/ord0616.p')

    I tried to create a "repro" of your query so we can work on it and try and improve it, but I got the best results by just adding text() and [1] to it, eg
    SELECT
    XREF_FileDataReference.XREF_FileData AS XrefFileData,
    InnerRowNode.value('(/D:Reference/D:File-num/text())[1]', 'int') AS FileNumber,
    InnerRowNode.value('(/D:Reference/D:Line-num/text())[1]', 'int') AS LineNumber
    FROM (
    In my main repro, even with a large piece of xml with 100,000 elements, there still wasn't much difference between the queries:
    USE tempdb
    GO
    IF NOT EXISTS ( SELECT * FROM sys.schemas WHERE name = 'XREF' )
    EXEC( 'CREATE SCHEMA XREF' )
    GO
    IF OBJECT_ID('XREF.XREF_FileData') IS NOT NULL DROP TABLE XREF.XREF_FileData
    CREATE TABLE XREF.XREF_FileData
    rowId INT IDENTITY,
    DataXref XML,
    XREF_FileData INT,
    XREF_FileEntry INT,
    CONSTRAINT PK_XREF_FileData PRIMARY KEY ( rowId )
    GO
    IF OBJECT_ID('XREF.XREF_MemberBuilt') IS NOT NULL DROP TABLE XREF.XREF_MemberBuilt
    CREATE TABLE XREF.XREF_MemberBuilt
    XREF_ProjectBuilt INT,
    XREF_FileData INT
    GO
    IF OBJECT_ID('XREF.XREF_FileEntry') IS NOT NULL DROP TABLE XREF.XREF_FileEntry
    CREATE TABLE XREF.XREF_FileEntry
    XREF_FileEntry INT
    GO
    -- Create larger piece of xml for repro
    ;WITH XMLNAMESPACES ( DEFAULT 'uri:schemas-progress-com:XREFD:0004' ), cte AS (
    SELECT TOP 100000 ROW_NUMBER() OVER ( ORDER BY ( SELECT 1 ) ) rn
    FROM master.sys.columns c1
    CROSS JOIN master.sys.columns c2
    CROSS JOIN master.sys.columns c3
    INSERT INTO XREF.XREF_FileData ( DataXref, XREF_FileData, XREF_FileEntry )
    SELECT
    SELECT
    CASE rn WHEN 9999 THEN 'ord/p/ord0616.p' ELSE CAST( rn AS VARCHAR(20) ) END AS "@Object-identifier",
    'RUN' AS "@Reference-type",
    SELECT
    rn AS "File-num",
    rn * 10 AS "Line-num"
    FOR XML PATH(''), TYPE
    ) AS "*"
    FROM cte
    FOR XML PATH('Reference'), ROOT('Source'), TYPE
    ).query('<Cross-reference xmlns="uri:schemas-progress-com:XREFD:0004">{.}</Cross-reference>'), 1, 100
    INSERT INTO XREF.XREF_FileEntry ( XREF_FileEntry )
    VALUES ( 100 )
    INSERT INTO XREF.XREF_MemberBuilt ( XREF_ProjectBuilt, XREF_FileData )
    VALUES ( 69, 1 )
    GO
    --SELECT * FROM XREF.XREF_FileData
    --SELECT * FROM XREF.XREF_FileEntry
    --SELECT * FROM XREF.XREF_MemberBuilt
    --GO
    -- Add primary XML index
    CREATE PRIMARY XML INDEX xidx_XREF_FileData ON XREF.XREF_FileData (DataXref)
    GO
    -- Add value, property and path xml indexes
    CREATE XML INDEX xvalidx_XREF_FileData ON XREF.XREF_FileData (DataXref)
    USING XML INDEX xidx_XREF_FileData FOR VALUE
    CREATE XML INDEX xpthidx_XREF_FileData ON XREF.XREF_FileData (DataXref)
    USING XML INDEX xidx_XREF_FileData FOR PATH
    CREATE XML INDEX xprpidx_XREF_FileData ON XREF.XREF_FileData (DataXref)
    USING XML INDEX xidx_XREF_FileData FOR PROPERTY
    GO
    :exit
    DBCC DROPCLEANBUFFERS
    DBCC FREEPROCCACHE
    GO
    DECLARE @p_ObjectIdentifierForReference varchar(500);
    SET @p_ObjectIdentifierForReference = 'ord/p/ord0616.p';
    ;WITH XMLNAMESPACES ('uri:schemas-progress-com:XREFD:0004' as D)
    SELECT
    XREF_FileDataReference.XREF_FileData AS XrefFileData,
    InnerRowNode.value('/D:Reference[1]/D:File-num[1]', 'int') AS FileNumber,
    InnerRowNode.value('/D:Reference[1]/D:Line-num[1]', 'int') AS LineNumber
    FROM (
    SELECT
    XREF.XREF_FileData.XREF_FileData,
    XREF.XREF_FileData.XREF_FileEntry,
    InnerRow.query('.') AS InnerRowNode
    FROM XREF.XREF_FileData
    OUTER APPLY DataXref.nodes('/D:Cross-reference/D:Source/D:Reference[@Object-identifier = sql:variable("@p_ObjectIdentifierForReference") and @Reference-type = "RUN"]') as T(InnerRow)
    WHERE DataXref.exist('/D:Cross-reference/D:Source/D:Reference[@Object-identifier = sql:variable("@p_ObjectIdentifierForReference") and @Reference-type = "RUN"]') = 1
    ) AS XREF_FileDataReference
    INNER JOIN XREF.XREF_MemberBuilt ON XREF_MemberBuilt.XREF_FileData = XREF_FileDataReference.XREF_FileData
    INNER JOIN XREF.XREF_FileEntry ON XREF_FileEntry.XREF_FileEntry = XREF_FileDataReference.XREF_FileEntry
    WHERE XREF_MemberBuilt.XREF_ProjectBuilt = 69
    OPTION( RECOMPILE, OPTIMIZE FOR (@p_ObjectIdentifierForReference = 'ord/p/ord0616.p') )
    GO
    DBCC DROPCLEANBUFFERS
    DBCC FREEPROCCACHE
    GO
    DECLARE @p_ObjectIdentifierForReference varchar(500);
    SET @p_ObjectIdentifierForReference = 'ord/p/ord0616.p';
    ;WITH XMLNAMESPACES ('uri:schemas-progress-com:XREFD:0004' as D)
    SELECT
    XREF_FileDataReference.XREF_FileData AS XrefFileData,
    InnerRowNode.value('(/D:Reference/D:File-num/text())[1]', 'int') AS FileNumber,
    InnerRowNode.value('(/D:Reference/D:Line-num/text())[1]', 'int') AS LineNumber
    FROM (
    SELECT
    XREF.XREF_FileData.XREF_FileData,
    XREF.XREF_FileData.XREF_FileEntry,
    InnerRow.query('.') AS InnerRowNode
    FROM XREF.XREF_FileData
    OUTER APPLY DataXref.nodes('/D:Cross-reference/D:Source/D:Reference[@Object-identifier = sql:variable("@p_ObjectIdentifierForReference") and @Reference-type = "RUN"]') as T(InnerRow)
    WHERE DataXref.exist('/D:Cross-reference/D:Source/D:Reference[@Object-identifier = sql:variable("@p_ObjectIdentifierForReference") and @Reference-type = "RUN"]') = 1
    ) AS XREF_FileDataReference
    INNER JOIN XREF.XREF_MemberBuilt ON XREF_MemberBuilt.XREF_FileData = XREF_FileDataReference.XREF_FileData
    INNER JOIN XREF.XREF_FileEntry ON XREF_FileEntry.XREF_FileEntry = XREF_FileDataReference.XREF_FileEntry
    WHERE XREF_MemberBuilt.XREF_ProjectBuilt = 69
    OPTION( RECOMPILE, OPTIMIZE FOR (@p_ObjectIdentifierForReference = 'ord/p/ord0616.p') )
    GO
    So I guess I'm saying I cannot reproduce your problem on SQL 2008 R2 or SQL 2012.  Does anything about this repro stand out as different from your situation?
    Looking at your query I would say you might consider the following:
    are you really seeing big differences in query duration?
    pretty much ignore estimated plan costs for xml queries
    consider breaking it up; eg carve off the xml then do the joins?  If poor cardinality estimation is part of the problem this might help
    Understand what PATH, PROPERTY and VALUE are for, then only create the ones you need
    do you really have the range of queries that requires all three?
    this is still a great article on xml indexes:
    http://technet.microsoft.com/en-us/library/ms191497.aspx
    What's performance like with the primary xml index only?
    If performance is that important, consider materialising the columns permanently
    I think the buffer_descriptors stuff is a distraction - mostly your cache is warm right?
    plan forcing could be a last resort
    Selective XML indexes in SQL 2012 onwards are great : )  much less storage required for example but much more specific

  • Using XML DB with Oracle Drive as Webdav client

    Hi all -
    I'm looking into using XML DB (10g) to store files so we can query their content via SQL/XPATH and then access/edit them via Webdav.
    Windows Vista makes this easy, since it can map a drive to a Webdav URL. Mac OSX can do a similar thing.
    Windows XP however can't do the drive mapping for WebDav on a port other than port 80, which is our setup.
    So I tried out Oracle Drive, which I stumbled across on some site somewhere, and it worked. But it was an old version, so I downloaded the "official" version from Oracle, which is v10.2.0.0.22. This version refuses to connect to XML DB no matter what I do. I've fiddled with authentication, proxies, and so on (there are several posts elsewhere with hints on this) but so far no joy.
    Has anyone had any experience making the latest version of Oracle Drive talk to XML DB?
    Many Thanks

    Thanks for replying.
    Yes, we may decide to move XML DB to port 80, but there are other services running on our server and such a move would be a significant hassle.
    As for Windows XP, it is not possible to do this: net use * http://server:8080/public
    This works on Vista, but it only works on XP if you use port 80.
    Note that XP has TWO built in Webdav clients: Web Folders (= Network Places) which is a feature in Explorer, and the Webdav Mini-Director which works at the file-system level. I don't think Web Folders can work for us since we need to be able to create a real filepath to give to our editor application. Maybe I'm wrong on that, but I can't figure it out.
    Oracle Drive seems to be a great solution, but I can't make the most recent version work (the old version worked but was buggy).
    Edited by: user10775425 on Jan 9, 2009 12:03 AM

Maybe you are looking for

  • Removing header and Footer in IE

    Hi i am generating a html document if i try to take print out the the URL is appearing at the bottom and the page name at the top of the resulting print page. any one can help how we can remove the header and footer data (which is in page setup) usin

  • How to lock data independently for several groups in Hyperion Planning?

    I 'm developing a forecast application using Hyperion Planning 9.3.1 where the users shall be able to enter their monthly forecast numbers. We have two groups of users. Each group may have up to two forecast updates per month. The groups are independ

  • Workflow Blocks

    I have a workflow in which I am utilizing a multiline container element for parallel processing.  According to my research, the BLOCK will be executed for each line in the container. My problem is that the BLOCK is currently defined as just one step.

  • ITunes Library.itl not valid music library file

    "iTunes Library.itl not valid music library file" I get this error almost everytime I restart my computer. When itunes makes the new ".itl" file, not all of my music is listed in the library. I have read through a large amount of the forum posts on t

  • OSB Business Service jms target

    Dear all, I have a business service in OSB, accepting messages, and putting them in a jms queue in j2ee. My question is, if it is possible somehow to declare as Endpoint URI the cluster address, so that the messages are balanced between the jms serve