This discussion is archived
9 Replies Latest reply: Apr 13, 2012 11:22 PM by 925053 RSS

string problem in xquery

925053 Newbie
Currently Being Moderated
i m using oxygen xml software i m new in xquery
my input file is
<transactions>
<transaction id = "1">
<name>oracle</name>
<meta>
<metadata>name</metadata>
<metadata>fame</metadata>
<metadata>same</metadata>
<metadata>game</metadata>
</meta>
</transaction>
<transaction id = "1">
<name>google</name>
<meta>
<metadata>rame</metadata>
<metadata>same</metadata>
<metadata>rain</metadata>
<metadata>drain</metadata>
<metadata>name</metadata>
</meta>
</transaction>
</transactions>

my xquery is:=

let $auction := doc("meta.xml") return
for $i in $auction/transactions//transaction
where contains(string(exactly-one($i)), "game")
return
$i/name/text()


the single string work ffine out put :=
goolge

but i give multiple string in palce of "game"

we give "name game "
it giving nothing output
plz help what i do in my xquerry
i wnat to print only name
not complete matching the string only matching word my word of the string first then match complete string .
what i do plz help me how i correct my code
  • 1. Re: string problem in xquery
    tsuji Journeyer
    Currently Being Moderated
    for $i in $auction/transactions//transaction
    There is no need of //. It is even dammaging to what you actually mean transaction as a direct child of transactions. This would do amply.
    for $i in $auction/transactions/transaction
    where contains(string(exactly-one($i)), "game")
    What is the point of exactly-one($i)? $i contains always only one item.

    Now the question: what do you mean by "name game"? That would literally mean the string() of $i contains a "substring" of "name game". That's not the need. So, what do you mean by "name game" functionally?
  • 2. Re: string problem in xquery
    925053 Newbie
    Currently Being Moderated
    SIR WHAT I WANT
    WHEN I PASS THE STRING "NAME GAME " TO XQUERY
    IS A STRING WHAEN I PASS OK
    THEN WE SEARCH "NAME" SEPRATE "GAME" SEPRATE AND "NAME GAME" SEPRATE OK
    BUT IT WORKING ONLY COMPLETE STRING NOT SUBSTRING PLZ HELP ME
    SIR
    I WANT SEARCH ALL STRING AND ITS SUB STRING ALSO FORM MY XML FILE FILE
    SO, SIR HOW I MODIFY MY XQUERY THAT THEY SEARCH ACCURATELY AND WHICH STRING FUNCTION USED HELP ME SIR PLZ
    HOW I MODIFY MY XQUERY
  • 3. Re: string problem in xquery
    tsuji Journeyer
    Currently Being Moderated
    You don't use all in uppercase. If you want to flame me, I can take it. But if you flame with all in uppercase, I would draw more sympathy from others that put you in a more disadvantage position than you deserve.

    Then, I don't understand what you are saying. Simple keywords for you to explain to the forum: is it an "and" or an "or" operation?
  • 4. Re: string problem in xquery
    925053 Newbie
    Currently Being Moderated
    I Really sorry sir that i usse all there in upper case really sorry sir
    sir , my Question is that i m wrriten one xquery which will give only complete string when i pass it and it search in xml file if it found they written the name ok sir
    what i want to do sir, i wana write a xquery which search a string i pass to them and also search the sub string also.


    for example :=
    i pass a string " google yahoo"
    then it seach my xml file i that way
    search "google"
    search "yahoo"
    and search "google yahoo"
    also that means sir
    my xquery search compleete string and also its sub string also sir.
    on more example sir :=
    whe i pass "cloud computing programming" then it
    search"cloud"
    search"computing"
    search"programing"
    search "cloud computing"
    search "cloud programing"
    seach"computing programing"
    seach"cloud computing programing"
    is there any way it write a xquery for that

    plz help me sir how i write xquery for that sir
  • 5. Re: string problem in xquery
    tsuji Journeyer
    Currently Being Moderated
    Okay I have only that much energy left to deal with this problem. But I must say it is not empty in technical significance, so bravo.

    I can only provide you with a function performing fully for an input up to 4 words separated by a single space. It leaves quite a bit to desire still, but it is not by itself too badly constructed. (I can only say that a notion of recursive function call is missing to complete the task to make it function in full generality.)

    Suppose the xml document look something like this rewritten to help testing more clearly.
    <!-- meta.xml -->
    <transactions>
        <transaction id="1">
            <name>oracle</name>
            <meta>
                <metadata>a</metadata>
                <metadata>b</metadata>
                <metadata>x y</metadata>
                <metadata>s t u v</metadata>
            </meta>
        </transaction>
        <transaction id = "2">
            <name>google</name>
            <meta>
                <metadata>a</metadata>
                <metadata>t u v</metadata>
                <metadata>p q r</metadata>
            </meta>
        </transaction>
    </transactions>
    This is the query with some sample testing data.
    declare variable $xfile:="meta.xml";
    
    (: declare variable $search:="a"; :)
    (: declare variable $search:="b"; :)
    (: declare variable $search:="b x"; :)
    (: declare variable $search:="p q w r"; :)
    (: declare variable $search:="t u v"; :)
    declare variable $search:="s x t y";
    
    declare function local:pgp_4($seq as item()*) as item()*
    {
        let $len := fn:count($seq)
        for $i in (1 to $len)
        return 
        (
            $seq[$i], 
            (
                for $j in (xs:int($i+1) to $len)
                return 
                (
                    fn:concat($seq[$i],' ',$seq[$j]),
                    (
                        for $k in (xs:int($j+1) to $len)
                        return
                        (
                            fn:concat($seq[$i],' ',$seq[$j],' ',$seq[$k]),
                            (
                                for $m in (xs:int($k+1) to $len)
                                return
                                (
                                    fn:concat($seq[$i],' ',$seq[$j],' ',$seq[$k],' ',$seq[$m])
                                )
                            )
                        )
                    )
                )
            )
        )
    };     
    
    <output> {
    let $auction := doc($xfile)
    let $seq:=tokenize($search,' ')
    let $seq_pgp_4:=local:pgp_4($seq)
    for $i in $auction/transactions/transaction
    where ($i/meta/metadata) = $seq_pgp_4
    return
    <find>{$i/name/text()}</find>
    }
    </output>
    You test various sample input or variants of them to verify the behaviour. For instance the last sample data will show the output like this.
    <output>
       <find>oracle</find>
    </output>
  • 6. Re: string problem in xquery
    925053 Newbie
    Currently Being Moderated
    thanks a lot sir really i great thsnk full to u sir
    sir i hve one doubt that when i pass a string suppose "x" ok sir string "x" in both the tranactions sir but they give the resulut nothing ok sir plz sir check
    and sir one more when i pass string "y" that string in transaction 1 but they dont give any output sir plz sir chek it once sir .
    i want one more modification thar sir if i use count i explain u sir that sir i what search string "x" ok sir that in but transaction how may times x comes based on that they print their result sir
    example sir := transaction 1 contain "x" =2 times and
    transaction 2 contain "x" = 3 times
    that mean sir transaction 2 name print first than transaction 1 name is it possible sir can we do that type thing in the same xquery some modifucation in same xquery.

    Edited by: MAXIMUM on Apr 12, 2012 11:20 PM
  • 7. Re: string problem in xquery
    tsuji Journeyer
    Currently Being Moderated
    sir i hve one doubt that when i pass a string suppose "x" ok sir string "x" in both the tranactions sir but they give the resulut nothing ok sir plz sir check
    and sir one more when i pass string "y" that string in transaction 1 but they dont give any output sir plz sir chek it once sir .
    Very well. When you pass "x" why should it match a text literally "x y"? Same for "y".

    Why do I say that? I asked you what do you mean by "name game"? And later asked if you mean an operation of "and" or "or"? What did you explain your intention?

    You said, taking a simpler version, when you put "cloud computing" you meant to searh "cloud" (x) and "computing" (y) and also "cloud computing" ("x y"). Now, if you now say x or y alone could sucessfully match "x y" already, why would you ever request to search "x y" ("clouding computing") as a whole?

    So that you now need a search string "x etc etc" can successfully match <metadata>x y</metadata>, there is no point to ask "x y z" to search "x", "y", "z", "x y", "x z", "y z" individually. The derived strings such as "x y" or "x z" are of no use at all because x is already successful and enough. That's absurd.

    If you now retract what you said in your third post, that's another story.

    If you yourself cannot formula a consistent description of what needed to do, chances are you are not going to solve the problem.

    The rest, I pass. And I would suggest you choose a forum with you native language as the operation language so that you can explain yourself better.
  • 8. Re: string problem in xquery
    925053 Newbie
    Currently Being Moderated
    i really sorry sir i got my point
    i extremlly sorry si rplz sir help me i accept my point sir plz sir help me i m taliking rubish thing i understud sir
    plz sir help me dont do with me like that sir
    i m very thank full to u sir to u slove my 90%of the problem sir plz sir
    i only single doubt sir
    i m counting the string sir the same as i m previous sir
    if i pass "x" string and they come in transaction 1=2 times and in transasction 2= 3 times than sir google print first then print oracle sir
    plz sir help me plz sir its my request sir how i modified my xquery that they print like that plz sir help me plz
  • 9. Re: string problem in xquery
    925053 Newbie
    Currently Being Moderated
    sir plz help me sir i really sry for that sir
    plz sir help how i do that sir plz sir

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points