[MarkLogic Dev General] Reg: Issue with xdmp:node-insert-child()

Ron Hitchens ron at ronsoft.com
Sat Aug 11 02:04:22 PDT 2012


   If you're concluding that it didn't work from the output
of this code:

	 xdmp:log(fn:concat("version-info before", $version-info)),
	 xdmp:node-insert-child($version-info,<nmsp:parent-id>{$parent-id}</nmsp:parent-id>),
	 xdmp:log(fn:concat("version-info after", $version-info)), 

   Then it will always appear to have "not worked".  XQuery
requests do not see the effects of their own updates.  The DB
changes are not visible, even to yourself, until the transaction
commits and this code is within the running transaction.  When this
request has successfully completed, you can do another query to see
the effect of the update. 

On Aug 11, 2012, at 3:43 AM, Gampa, Sriram wrote:

> 
> Hi Danny,
> 
> Thanks for the reply.  Below is the code snippet that I have written for updating the document
> 
> let $version-info-uri := get:build-next-version-info-uri($document_data) 
> (: This returns the uri of latest version available in database e.g. "/content/documents/sd/62211250/ ABCD13255DEFG-version-info-7.xml :)
> 
> let $version-info := fn:doc($version-info-uri)/pce:version-info
> let $parent-standard-id as  xs:unsignedLong := $document_data/nmsp:parent-id (: This value is returning a unsigned value "132456666267788" :)
> let $uri := set:build-document-uri$document_data)
> let $now := fn:current-dateTime()
> let $old-doc-exists as xs:boolean := fn:doc-available($uri)
>  let $existing-date as xs:dateTime := (fn:doc($uri)/nmsp:document/nmsp:modified-date, $now)[1]
>  let $new-date as xs:dateTime := (set:to-dateTime(($document_data /modifiedDate), $now)[1]
>  let $existing-description as xs:string := fn:string(fn:doc($uri)/ nmsp:document /nmsp:document_description)
>  let $new-description as xs:string := fn:string($new-document/ nmsp:document_description)
> 
> return
>    (: insert the doc if there is no previous version or the new version has a newer modified date and the text of the description
>       is different :)
>    if (fn:not($old-doc-exists) or ($new-date > $existing-date and ($new-date != $now))) then 
>   (
>     try{
>       if ($old-doc-exists) then
>        (
> 	if ($existing-description ne $new-description) then
>          (
> 
> 	xdmp:log(fn:concat("version-info before", $version-info)),
> 	 xdmp:node-insert-child($version-info,<nmsp:parent-id>{$parent-id}</nmsp:parent-id>),
> 	xdmp:log(fn:concat("version-info after", $version-info)), 
> 	xdmp:log(fn:concat("parent-document-id::",$parent-id)),
> 
>        )
>       else( (: replacing the document directly without update :))
>  }
> catch($ex) {xdmp:log($ex)}
> )
> else()
> 
> The above code is not inserting the parent-id in the version-info document and it is not reporting any error at the time of insertion.
> 
> 
> Thanks,
> Sriram Gampa
> 
> 
> 
> 
> 
> 
> -----Original Message-----
> From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of general-request at developer.marklogic.com
> Sent: Friday, August 10, 2012 10:06 PM
> To: general at developer.marklogic.com
> Subject: General Digest, Vol 98, Issue 30
> 
> Send General mailing list submissions to
> 	general at developer.marklogic.com
> 
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://developer.marklogic.com/mailman/listinfo/general
> or, via email, send a message with subject or body 'help' to
> 	general-request at developer.marklogic.com
> 
> You can reach the person managing the list at
> 	general-owner at developer.marklogic.com
> 
> When replying, please edit your Subject line so it is more specific than "Re: Contents of General digest..."
> 
> 
> Today's Topics:
> 
>   1. Re: Reg: Issue with xdmp:node-insert-child() (Danny Sokolsky)
>   2. search:parse parenthetical grouping (Will Thompson)
>   3. Re: search:parse parenthetical grouping (Michael Blakeley)
>   4. Re: search:parse parenthetical grouping (Danny Sokolsky)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Fri, 10 Aug 2012 15:17:38 -0700
> From: Danny Sokolsky <Danny.Sokolsky at marklogic.com>
> Subject: Re: [MarkLogic Dev General] Reg: Issue with
> 	xdmp:node-insert-child()
> To: MarkLogic Developer Discussion <general at developer.marklogic.com>
> Message-ID:
> 	<C9924D15B04672479B089F7D55FFC1322264292B51 at EXCHG-BE.marklogic.com>
> Content-Type: text/plain; charset="us-ascii"
> 
> Hi Siriam,
> 
> Since you did not give the whole code or tell us the error you are seeing, it is hard to say.  For example, in the code you have, there is no $parent-id variable bound.  The basic idea you have works, as this code inserts a child node after the root node:
> 
> 
> xdmp:document-insert("/testdevlist.xml", <version-info xmlns="http://namespace">
>                <id>ABCD13255DEFG</id>
>                <additions/>
>                <updates/>
>                <deletes/>
>  </version-info>
> );
> 
> declare namespace pce="http://namespace"; let $version-info := fn:doc("/testdevlist.xml")/pce:version-info
> return xdmp:node-insert-child($version-info, <foo/>);
> 
> doc("/testdevlist.xml")
> =>
> <?xml version="1.0" encoding="UTF-8"?>
> <version-info xmlns="http://namespace">
>  <id>ABCD13255DEFG</id>
>  <additions/>
>  <updates/>
>  <deletes/>
>  <foo xmlns=""/>
> </version-info>
> 
> So I maybe if you simplify your query and then post some code along with results and/or error messages, we can help figure it out.
> 
> -Danny
> 
> From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of Gampa, Sriram
> Sent: Friday, August 10, 2012 2:22 PM
> To: general at developer.marklogic.com
> Subject: [MarkLogic Dev General] Reg: Issue with xdmp:node-insert-child()
> 
> Hi All,
> 
> I'm having an issue while inserting an element into a node using xdmp:node-insert-child().
> 
> My xml structure is as below
> 
> <version-info xmlns="http://namespace">
>                <id>ABCD13255DEFG</id>
>                <additions/>
>                <updates/>
>                <deletes/>
>  </version-info>
> 
> I'm trying to insert <parent-id> 13242682898790</parent-id> into the <version-info> as child using the xdmp:node-insert-child() as part of my code but the node is not getting inserted into the version-info xml. But when I tried to the same through CQ its working fine.
> 
> 
> let $version-info-uri := "/content/documents/sd/62211250/ ABCD13255DEFG-version-info-7.xml"
> let $log1 := xdmp:log(fn:concat("Update Note: Version Info URI", $version-info-uri)) let $version-info := fn:doc($version-info-uri)/pce:version-info
> ...
> ...
> xdmp:log(fn:concat("version-info before", $version-info)), xdmp:node-insert-child($version-info,<nmsp:parent-id>{$parent-id}</nmsp:parent-id>),
> xdmp:log(fn:concat("version-info after", $version-info)), xdmp:log(fn:concat("parent-document-id::",$parent-id)),
> 
> Could please let me know what is the issue with the above code.
> 
> Thanks,
> Sriram Gampa
> 
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: http://developer.marklogic.com/pipermail/general/attachments/20120810/bd6f3c11/attachment-0001.html 
> 
> ------------------------------
> 
> Message: 2
> Date: Fri, 10 Aug 2012 23:15:03 +0000
> From: Will Thompson <wthompson at jonesmcclure.com>
> Subject: [MarkLogic Dev General] search:parse parenthetical grouping
> To: MarkLogic Developer Discussion <general at developer.marklogic.com>
> Message-ID:
> 	<7A4B442E791E444DB6CA1B9BFA29E92B36154916 at redman.jmpone.local>
> Content-Type: text/plain; charset="us-ascii"
> 
> I need to prevent paren grouping from happening when the parens are part of a string - typically it's a reference-type number. I can't think of a situation where this would be desirable anyway:
> 
> search:parse('123.4(5)')
> => cts:and-query((cts:word-query("123.4(5"), cts:word-query(")")))
> 
> If I change the grammar to require a space on either or both sides of the paren, then it will always break some legitimate grouping case like "(hello AND world)".
> 
> Is there any way to control these grammar options a little further? It would be easy if you could just use regexes in the grammar options, i.e.:
> 
> <starter strength="30" apply="grouping" delimiter="(^|\s)/)">/(($|\s)</starter>
> 
> Thanks,
> 
> Will
> 
> 
> 
> ------------------------------
> 
> Message: 3
> Date: Fri, 10 Aug 2012 16:59:22 -0700
> From: Michael Blakeley <mike at blakeley.com>
> Subject: Re: [MarkLogic Dev General] search:parse parenthetical
> 	grouping
> To: MarkLogic Developer Discussion <general at developer.marklogic.com>
> Message-ID: <88E99246-7082-4161-8D76-759A2371438E at blakeley.com>
> Content-Type: text/plain; charset=us-ascii
> 
> That does seem undesirable. I was going to refer you to https://github.com/mblakele/xqysp but it doesn't do much better - unless you can get your users to quote the number?
> 
> import module namespace qe="com.blakeley.xqysp.query-eval"
> at "query-eval.xqy";
> 
> qe:parse('123.4(5)'),
> qe:parse('"123.4(5)"')
> =>
> cts:and-query((cts:word-query("123", ("lang=en"), 1), cts:word-query("4", ("lang=en"), 1), cts:word-query("5", ("lang=en"), 1)), ()) cts:word-query("123.4(5)", ("lang=en"), 1)
> 
> You can pass that output to search:resolve(), with pretty much the same semantics as search:search.
> 
> -- Mike
> 
> On 10 Aug 2012, at 16:15 , Will Thompson wrote:
> 
>> I need to prevent paren grouping from happening when the parens are part of a string - typically it's a reference-type number. I can't think of a situation where this would be desirable anyway:
>> 
>> search:parse('123.4(5)')
>> => cts:and-query((cts:word-query("123.4(5"), cts:word-query(")")))
>> 
>> If I change the grammar to require a space on either or both sides of the paren, then it will always break some legitimate grouping case like "(hello AND world)".
>> 
>> Is there any way to control these grammar options a little further? It would be easy if you could just use regexes in the grammar options, i.e.:
>> 
>> <starter strength="30" apply="grouping" 
>> delimiter="(^|\s)/)">/(($|\s)</starter>
>> 
>> Thanks,
>> 
>> Will
>> 
>> _______________________________________________
>> General mailing list
>> General at developer.marklogic.com
>> http://developer.marklogic.com/mailman/listinfo/general
>> 
> 
> 
> 
> ------------------------------
> 
> Message: 4
> Date: Fri, 10 Aug 2012 19:05:42 -0700
> From: Danny Sokolsky <Danny.Sokolsky at marklogic.com>
> Subject: Re: [MarkLogic Dev General] search:parse parenthetical
> 	grouping
> To: MarkLogic Developer Discussion <general at developer.marklogic.com>
> Message-ID:
> 	<C9924D15B04672479B089F7D55FFC1322264292BB1 at EXCHG-BE.marklogic.com>
> Content-Type: text/plain; charset="us-ascii"
> 
> It probably won't work for you, but one idea is to change the starter for grouping to have different delimiting chars.  For example, 2 parens:
> 
> <starter strength="30" apply="grouping" delimiter="))">((</starter>
> 
> It might be better than a space....
> 
> -Danny
> 
> -----Original Message-----
> From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of Michael Blakeley
> Sent: Friday, August 10, 2012 4:59 PM
> To: MarkLogic Developer Discussion
> Subject: Re: [MarkLogic Dev General] search:parse parenthetical grouping
> 
> That does seem undesirable. I was going to refer you to https://github.com/mblakele/xqysp but it doesn't do much better - unless you can get your users to quote the number?
> 
> import module namespace qe="com.blakeley.xqysp.query-eval"
> at "query-eval.xqy";
> 
> qe:parse('123.4(5)'),
> qe:parse('"123.4(5)"')
> =>
> cts:and-query((cts:word-query("123", ("lang=en"), 1), cts:word-query("4", ("lang=en"), 1), cts:word-query("5", ("lang=en"), 1)), ()) cts:word-query("123.4(5)", ("lang=en"), 1)
> 
> You can pass that output to search:resolve(), with pretty much the same semantics as search:search.
> 
> -- Mike
> 
> On 10 Aug 2012, at 16:15 , Will Thompson wrote:
> 
>> I need to prevent paren grouping from happening when the parens are part of a string - typically it's a reference-type number. I can't think of a situation where this would be desirable anyway:
>> 
>> search:parse('123.4(5)')
>> => cts:and-query((cts:word-query("123.4(5"), cts:word-query(")")))
>> 
>> If I change the grammar to require a space on either or both sides of the paren, then it will always break some legitimate grouping case like "(hello AND world)".
>> 
>> Is there any way to control these grammar options a little further? It would be easy if you could just use regexes in the grammar options, i.e.:
>> 
>> <starter strength="30" apply="grouping" 
>> delimiter="(^|\s)/)">/(($|\s)</starter>
>> 
>> Thanks,
>> 
>> Will
>> 
>> _______________________________________________
>> General mailing list
>> General at developer.marklogic.com
>> http://developer.marklogic.com/mailman/listinfo/general
>> 
> 
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general
> 
> 
> ------------------------------
> 
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general
> 
> 
> End of General Digest, Vol 98, Issue 30
> ***************************************
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general

---
Ron Hitchens {mailto:ron at ronsoft.com}   Ronsoft Technologies
     +44 7879 358 212 (voice)          http://www.ronsoft.com
     +1 707 924 3878 (fax)              Bit Twiddling At Its Finest
"No amount of belief establishes any fact." -Unknown






More information about the General mailing list