I meant to say I should not have posted this question on this forum.

————————————————
Kashif Khan, PMI-ACP
Sr. Solution Architect
Publishing Technology

Houghton Mifflin Harcourt
9400 South Park Center Loop
Orlando, FL 32819
Office: 407.345.3420
Mobile: 407.949.4697
hmhco.com

From: <Khan>, Kashif Khan <[email protected]<mailto:[email protected]>>
Reply-To: MarkLogic Developer Discussion 
<[email protected]<mailto:[email protected]>>
Date: Tuesday, May 28, 2013 2:32 PM
To: MarkLogic Developer Discussion 
<[email protected]<mailto:[email protected]>>
Subject: Re: [MarkLogic Dev General] Unable to get the value of Element Š.

Thanks but here is the answer to my question. First off I should have posted 
this question here as this is a pure xQuery question.

This answer was provided by David Lee on 
[email protected]<mailto:[email protected]>. This solution work for me.

In pure XQuery what  you are attempting will not work ... xpath cannot have an 
accessor element which is dynamic ...
but you can do something similar.

Note: The following is hand typed by memory , might have typos.  Also this 
assumes your document is in no namespace.
Changes need to be made to accomidate namespaces.

First off you want to return a QName not an element for getHierarchyElements



declare function oxy:getHierarchyElements() as xs:QName {


let $TagName := "Chapter Title"


        (:removing the space between Chapter and Title:)
      let $tokenizedString := fn:tokenize(($TagName), '\s')
        let $concatString :=  fn:concat($tokenizedString[1], 
$tokenizedString[2])
         return
            fn:QName("",$concatString() )
};


Then you need to change your xpath to use node-name



declare function oxy:getLevel($document as xs:string){
    let $file := doc($document)
    let $hierarchy := oxy:getHierarchyElements()
    return
            $file/report/body/row/*[ node-name(.) eq $hierarchy ]
};

————————————————
Kashif Khan, PMI-ACP
Sr. Solution Architect
Publishing Technology

Houghton Mifflin Harcourt
9400 South Park Center Loop
Orlando, FL 32819
Office: 407.345.3420
Mobile: 407.949.4697
hmhco.com

From: Damon Feldman 
<[email protected]<mailto:[email protected]>>
Reply-To: MarkLogic Developer Discussion 
<[email protected]<mailto:[email protected]>>
Date: Tuesday, May 28, 2013 2:27 PM
To: MarkLogic Developer Discussion 
<[email protected]<mailto:[email protected]>>
Subject: Re: [MarkLogic Dev General] Unable to get the value of Element Š.


Kashif,

You need to get XML into the system to use XQuery – XQuery does not work on 
strings that happen to have XML in them, but on XML documents. MarkLogic adds 
“unquote,” “document-insert” etc. because there is now method in the XQuery 
spec to add XML.

You must use implementation-specific methods to get the XML into the system in 
the first place because XQuery as a spec does not define add/insert functions.

Yours,
Damon

From:[email protected]<mailto:[email protected]>
 [mailto:[email protected]] On Behalf Of Khan, Kashif
Sent: Friday, May 24, 2013 6:39 PM
To: MarkLogic Developer Discussion
Cc: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Unable to get the value of Element Š.

Yes I looked into that but the problem is that I can not use any MarkLogic 
functions.
Best Regards,
Kashif Khan

Sent from my iPhone

On May 24, 2013, at 6:36 PM, "Danny Sokolsky" 
<[email protected]<mailto:[email protected]>> wrote:
Hi Kashif,

In that case, you can use xdmp:unquote, which parses a string as XML.  
Something like:

let $document :=
"<report>
        <body>
        <row>
            <ChapterTitle>Front Matter</ChapterTitle>
</row>
</body>
</report>"
let $document2 := xdmp:unquote($document)
return $document2//ChapterTitle

From:[email protected]<mailto:[email protected]>
 [mailto:[email protected]] On Behalf Of Khan, Kashif
Sent: Friday, May 24, 2013 3:31 PM
To: MarkLogic Developer Discussion
Cc: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Unable to get the value of Element Š.

Danny I am trying to resolve a problem where I have to convert text string into 
the tag name and then use that to extract the value from the XML.
Best Regards,
Kashif Khan

Sent from my iPhone

On May 24, 2013, at 5:47 PM, "Danny Sokolsky" 
<[email protected]<mailto:[email protected]>> wrote:
Hi Kashif,

Why not treat your XML as XML instead of a string.  Then you can just use 
XPath.  Something like:

let $document :=
<report>
        <body>
        <row>
            <ChapterTitle>Front Matter</ChapterTitle>
</row>
</body>
</report>
return $document//ChapterTitle
=>
<ChapterTitle>Front Matter</ChapterTitle>

-Danny

From:[email protected]<mailto:[email protected]>
 [mailto:[email protected]] On Behalf Of Khan, Kashif
Sent: Friday, May 24, 2013 2:38 PM
To: MarkLogic Developer Discussion
Subject: [MarkLogic Dev General] Unable to get the value of Element Š.

Hello Everyone, I am having a problem extracting value from an element
Here is the XML on which I am trying to run my query


Let $document := "<report>
        <body>
        <row>
            <ChapterTitle>Front Matter</ChapterTitle>
</row

</body>

</report>"



These are the functions that I have written to extract the value of the 
"ChapterTitle" Tag



declare functionoxy:getHierarchyElements() {


let$TagName := "Chapter Title"


        (:removing the space between Chapter and Title:)

let$tokenizedString := fn:tokenize(($TagName), '\s')
        let $concatString :=  fn:concat($tokenizedString[1], 
$tokenizedString[2])
         return
            element {$concatString} {''}

};

declare function oxy:getLevel($document as xs:string){
    let$file :=doc($document)
    let$hierarchy :=oxy:getHierarchyElements()
    return
            $file/report/body/row/$hierarchy
};



When I call oxy:getLevel($oxy:document) I get <ChapterTitle/>  instead of 
"Front Matter" from the XML file.



If I replace   $file/report/body/row/$hierarchy with  
$file/report/body/row/ChapterTitle I get the correct value.



Thanks for your help in advance


————————————————
Kashif Khan
_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to