Dear list,
I have an XML document in the database which contains datas that has the form below. The attribute "site" represents the location from where the captured data originates, the element "num" contains the number of the measure (the identifier. it is the same as a primary key), "value" contains the value (xs:token even if no WS are allowed inside of it) and "time" the time of the acquisition (xs:dateTime).
<datas site="xxx"> <data> <num>5</num> <value>700</value> <time>2013-05-01T21:43:13</time> </data> ... </datas>
I want to update specific values at a given time. I usually have 300 or 400 values to update. That means, changing the content of child elements "value" and "time" but not "num" of many "data" elements. I wrote an XQuery script named update.xq that I placed in the Web repository. It will receive the site, the time, the numbers of the values to be updated (PK) and of course the values themselves as variables with a POST HTTP request. I do not use much typing as pretty much everything is xs:string. I guess it could be better but my problem is not there.
declare variable $nums as xs:string external; declare variable $values as xs:string external; declare variable $time as xs:dateTime external; declare variable $site as xs:token external;
let $n := tokenize($nums,','), $v := tokenize($values,',') return for $x at $i in $n return (replace value of node /datas[@site=$site]/data[num=$x]/value with $v[$i], replace value of node /datas[@site=$site]/data[num=$x]/time with $time)
The problem is that sometimes it works and sometimes it gives me an HTTP 400 error with body :
Stopped at update.xq, 9/73: [XUTY0008] Single element, text, attribute, comment or pi expected as replace target.
I know the replace target has to have the expected format and I think it has. I don't understand why I get this. I though it was due to too long stuff so I divided the list of datas to update into sublists of size 50. Now, the problem appears sometimes but not everytime. When I use another XQuery script test.xq to display what was received, everything looks ok. The test script is :
declare variable $nums as xs:string external; declare variable $values as xs:string external; declare variable $time as xs:dateTime external; declare variable $site as xs:token external; let $n := tokenize($nums,','), $v := tokenize($values,',') return for $x at $i in $n return ($x,$v[$i])
For example, this update is ok:
<?xml version="1.0"?> <run xmlns="http://basex.org/rest"> <text>update.xq</text> <variable name="site" value="xxx"/> <variable name="time" value="2013-05-02T09:58:38"/> <variable name="nums" value="439,375,128,426,362,243,115,413,349,230,102,400,336,272,217,153,387,259,204,76,438,374,255,127,425,361,114,412,229,101,399,335,271,216,152,386,258,203,75,11,437,373,254,126,424,360,113,411,228,100"/> <variable name="values" value="1515.200,408,true,973.806,3.892,false,false,0.000,0.0,6,true,430.400,false,2,327.670,true,410,true,45.410,true,0.992,408,false,false,575.060,3.545,false,0.995,87.270,false,436.800,false,94.000,45.410,false,410,false,14.135,true,true,2152.800,0,true,true,4.924,3.639,false,0.992,87.070,true" /> </run>
But this one is not :
<?xml version="1.0"?> <run xmlns="http://basex.org/rest"> <text>update.xq</text> <variable name="site" value="xxx"/> <variable name="time" value="2013-05-02T09:58:38"/> <variable name="nums" value="36,398,334,215,385,202,74,436,372,253,125,423,359,240,112,442,410,378,227,131,99,429,397,365,333,214,118,54,416,384,352,288,233,201,105,73,9,435,403,371,339,275,220,156,124,422,390,358,294,239"/> <variable name="values" value="true,428.400,false,45.059,410,12.710,true,2152.800,0,false,false,2.437,-0.101,false,true,4907.327,0.994,409,0.000,false,true,1012.437,448.800,0.000,false,62.260,false,true,304.600,410,0.0,58,87.249,13.180,true,true,true,2152.800,454.200,0,false,2,757,true,true,0.326,0.000,0.0,41,false" /> </run>
I think those documents are similar and I shouldn't see a difference. Either it works for both of them or it doesn't.
Any idea to point me in the right direction is welcome.
Thank in advance,
Ludovic Kuty
I have copy/pasted the test with updates that contains 20 pairs num, value. That means 40 XQUF replace every time (alter the "value" and the "time").
For most of them you can see a line that looks like :
STATUS: {[72,84,84,80,47,49,46,49],200,[79,75]} BODY:
Where the HTTP status code is 200 and there is no HTTP response body. That means that everything was alright.
And sometimes, you see :
STATUS: {[72,84,84,80,47,49,46,49],400,[66,97,100,32,82,101,113,117,101,115,116]} BODY: Stopped at update.xq, 9/73: [XUTY0008] Single element, text, attribute, comment or pi expected as replace target.
Where the HTTP status code is 400 and the HTTP response body indicates the error.
On 02 May 2013, at 10:27, Ludovic Kuty wrote:
Dear list,
I have an XML document in the database which contains datas that has the form below. The attribute "site" represents the location from where the captured data originates, the element "num" contains the number of the measure (the identifier. it is the same as a primary key), "value" contains the value (xs:token even if no WS are allowed inside of it) and "time" the time of the acquisition (xs:dateTime).
<datas site="xxx"> <data> <num>5</num> <value>700</value> <time>2013-05-01T21:43:13</time> </data> ... </datas>
I want to update specific values at a given time. I usually have 300 or 400 values to update. That means, changing the content of child elements "value" and "time" but not "num" of many "data" elements. I wrote an XQuery script named update.xq that I placed in the Web repository. It will receive the site, the time, the numbers of the values to be updated (PK) and of course the values themselves as variables with a POST HTTP request. I do not use much typing as pretty much everything is xs:string. I guess it could be better but my problem is not there.
declare variable $nums as xs:string external; declare variable $values as xs:string external; declare variable $time as xs:dateTime external; declare variable $site as xs:token external;
let $n := tokenize($nums,','), $v := tokenize($values,',') return for $x at $i in $n return (replace value of node /datas[@site=$site]/data[num=$x]/value with $v[$i], replace value of node /datas[@site=$site]/data[num=$x]/time with $time)
The problem is that sometimes it works and sometimes it gives me an HTTP 400 error with body :
Stopped at update.xq, 9/73: [XUTY0008] Single element, text, attribute, comment or pi expected as replace target.
I know the replace target has to have the expected format and I think it has. I don't understand why I get this. I though it was due to too long stuff so I divided the list of datas to update into sublists of size 50. Now, the problem appears sometimes but not everytime. When I use another XQuery script test.xq to display what was received, everything looks ok. The test script is :
declare variable $nums as xs:string external; declare variable $values as xs:string external; declare variable $time as xs:dateTime external; declare variable $site as xs:token external; let $n := tokenize($nums,','), $v := tokenize($values,',') return for $x at $i in $n return ($x,$v[$i])
For example, this update is ok:
<?xml version="1.0"?>
<run xmlns="http://basex.org/rest"> <text>update.xq</text> <variable name="site" value="xxx"/> <variable name="time" value="2013-05-02T09:58:38"/> <variable name="nums" value="439,375,128,426,362,243,115,413,349,230,102,400,336,272,217,153,387,259,204,76,438,374,255,127,425,361,114,412,229,101,399,335,271,216,152,386,258,203,75,11,437,373,254,126,424,360,113,411,228,100"/> <variable name="values" value="1515.200,408,true,973.806,3.892,false,false,0.000,0.0,6,true,430.400,false,2,327.670,true,410,true,45.410,true,0.992,408,false,false,575.060,3.545,false,0.995,87.270,false,436.800,false,94.000,45.410,false,410,false,14.135,true,true,2152.800,0,true,true,4.924,3.639,false,0.992,87.070,true" /> </run>
But this one is not :
<?xml version="1.0"?>
<run xmlns="http://basex.org/rest"> <text>update.xq</text> <variable name="site" value="xxx"/> <variable name="time" value="2013-05-02T09:58:38"/> <variable name="nums" value="36,398,334,215,385,202,74,436,372,253,125,423,359,240,112,442,410,378,227,131,99,429,397,365,333,214,118,54,416,384,352,288,233,201,105,73,9,435,403,371,339,275,220,156,124,422,390,358,294,239"/> <variable name="values" value="true,428.400,false,45.059,410,12.710,true,2152.800,0,false,false,2.437,-0.101,false,true,4907.327,0.994,409,0.000,false,true,1012.437,448.800,0.000,false,62.260,false,true,304.600,410,0.0,58,87.249,13.180,true,true,true,2152.800,454.200,0,false,2,757,true,true,0.326,0.000,0.0,41,false" /> </run>
I think those documents are similar and I shouldn't see a difference. Either it works for both of them or it doesn't.
Any idea to point me in the right direction is welcome.
Thank in advance,
Ludovic Kuty
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
I forgot to specify the version. It is BaseX 7.7 beta.
More specifically, it came form the file BaseX77-20130414.171509.zip
On 02 May 2013, at 10:35, Ludovic Kuty wrote:
I have copy/pasted the test with updates that contains 20 pairs num, value. That means 40 XQUF replace every time (alter the "value" and the "time").
For most of them you can see a line that looks like :
STATUS: {[72,84,84,80,47,49,46,49],200,[79,75]} BODY:
Where the HTTP status code is 200 and there is no HTTP response body. That means that everything was alright.
And sometimes, you see :
STATUS: {[72,84,84,80,47,49,46,49],400,[66,97,100,32,82,101,113,117,101,115,116]} BODY: Stopped at update.xq, 9/73: [XUTY0008] Single element, text, attribute, comment or pi expected as replace target.
Where the HTTP status code is 400 and the HTTP response body indicates the error.
On 02 May 2013, at 10:27, Ludovic Kuty wrote:
Dear list,
I have an XML document in the database which contains datas that has the form below. The attribute "site" represents the location from where the captured data originates, the element "num" contains the number of the measure (the identifier. it is the same as a primary key), "value" contains the value (xs:token even if no WS are allowed inside of it) and "time" the time of the acquisition (xs:dateTime).
<datas site="xxx"> <data> <num>5</num> <value>700</value> <time>2013-05-01T21:43:13</time> </data> ... </datas>
I want to update specific values at a given time. I usually have 300 or 400 values to update. That means, changing the content of child elements "value" and "time" but not "num" of many "data" elements. I wrote an XQuery script named update.xq that I placed in the Web repository. It will receive the site, the time, the numbers of the values to be updated (PK) and of course the values themselves as variables with a POST HTTP request. I do not use much typing as pretty much everything is xs:string. I guess it could be better but my problem is not there.
declare variable $nums as xs:string external; declare variable $values as xs:string external; declare variable $time as xs:dateTime external; declare variable $site as xs:token external;
let $n := tokenize($nums,','), $v := tokenize($values,',') return for $x at $i in $n return (replace value of node /datas[@site=$site]/data[num=$x]/value with $v[$i], replace value of node /datas[@site=$site]/data[num=$x]/time with $time)
The problem is that sometimes it works and sometimes it gives me an HTTP 400 error with body :
Stopped at update.xq, 9/73: [XUTY0008] Single element, text, attribute, comment or pi expected as replace target.
I know the replace target has to have the expected format and I think it has. I don't understand why I get this. I though it was due to too long stuff so I divided the list of datas to update into sublists of size 50. Now, the problem appears sometimes but not everytime. When I use another XQuery script test.xq to display what was received, everything looks ok. The test script is :
declare variable $nums as xs:string external; declare variable $values as xs:string external; declare variable $time as xs:dateTime external; declare variable $site as xs:token external; let $n := tokenize($nums,','), $v := tokenize($values,',') return for $x at $i in $n return ($x,$v[$i])
For example, this update is ok:
<?xml version="1.0"?>
<run xmlns="http://basex.org/rest"> <text>update.xq</text> <variable name="site" value="xxx"/> <variable name="time" value="2013-05-02T09:58:38"/> <variable name="nums" value="439,375,128,426,362,243,115,413,349,230,102,400,336,272,217,153,387,259,204,76,438,374,255,127,425,361,114,412,229,101,399,335,271,216,152,386,258,203,75,11,437,373,254,126,424,360,113,411,228,100"/> <variable name="values" value="1515.200,408,true,973.806,3.892,false,false,0.000,0.0,6,true,430.400,false,2,327.670,true,410,true,45.410,true,0.992,408,false,false,575.060,3.545,false,0.995,87.270,false,436.800,false,94.000,45.410,false,410,false,14.135,true,true,2152.800,0,true,true,4.924,3.639,false,0.992,87.070,true" /> </run>
But this one is not :
<?xml version="1.0"?>
<run xmlns="http://basex.org/rest"> <text>update.xq</text> <variable name="site" value="xxx"/> <variable name="time" value="2013-05-02T09:58:38"/> <variable name="nums" value="36,398,334,215,385,202,74,436,372,253,125,423,359,240,112,442,410,378,227,131,99,429,397,365,333,214,118,54,416,384,352,288,233,201,105,73,9,435,403,371,339,275,220,156,124,422,390,358,294,239"/> <variable name="values" value="true,428.400,false,45.059,410,12.710,true,2152.800,0,false,false,2.437,-0.101,false,true,4907.327,0.994,409,0.000,false,true,1012.437,448.800,0.000,false,62.260,false,true,304.600,410,0.0,58,87.249,13.180,true,true,true,2152.800,454.200,0,false,2,757,true,true,0.326,0.000,0.0,41,false" /> </run>
I think those documents are similar and I shouldn't see a difference. Either it works for both of them or it doesn't.
Any idea to point me in the right direction is welcome.
Thank in advance,
Ludovic Kuty
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
Dear Ludovic,
The error message indicates that the XPath /datas[@site=$site]/data[num=$x]/value return not just a single element, but multiple instead. Could it be that for some values of @site and @num you have multiple datas. This would explain why it sometimes happens and sometimes it does not. It is hard to tell as we don't have the whole xml data file, but just a snippet. Maybe you could test this and instead of updating your XML simply output /datas[@site=$site]/data[num=$x]/value You can then check if you have multiple values and then maybe you want to change your xml (if this should be invalid) or you have to change your XQuery (you could do a FLOWR expression to update all data nodes).
Cheers, Dirk
On Thu, May 2, 2013 at 10:45 AM, Ludovic Kuty mailing@kuty.be wrote:
I forgot to specify the version. It is BaseX 7.7 beta.
More specifically, it came form the file BaseX77-20130414.171509.zip
On 02 May 2013, at 10:35, Ludovic Kuty wrote:
I have copy/pasted the test with updates that contains 20 pairs num,
value. That means 40 XQUF replace every time (alter the "value" and the "time").
For most of them you can see a line that looks like :
STATUS: {[72,84,84,80,47,49,46,49],200,[79,75]} BODY:
Where the HTTP status code is 200 and there is no HTTP response body.
That means that everything was alright.
And sometimes, you see :
STATUS:
{[72,84,84,80,47,49,46,49],400,[66,97,100,32,82,101,113,117,101,115,116]} BODY: Stopped at update.xq, 9/73:
[XUTY0008] Single element, text, attribute, comment or pi expected as
replace target.
Where the HTTP status code is 400 and the HTTP response body indicates
the error.
On 02 May 2013, at 10:27, Ludovic Kuty wrote:
Dear list,
I have an XML document in the database which contains datas that has
the form below. The attribute "site" represents the location from where the captured data originates, the element "num" contains the number of the measure (the identifier. it is the same as a primary key), "value" contains the value (xs:token even if no WS are allowed inside of it) and "time" the time of the acquisition (xs:dateTime).
<datas site="xxx"> <data> <num>5</num> <value>700</value> <time>2013-05-01T21:43:13</time> </data> ... </datas>
I want to update specific values at a given time. I usually have 300 or
400 values to update. That means, changing the content of child elements "value" and "time" but not "num" of many "data" elements. I wrote an XQuery script named update.xq that I placed in the Web repository. It will receive the site, the time, the numbers of the values to be updated (PK) and of course the values themselves as variables with a POST HTTP request. I do not use much typing as pretty much everything is xs:string. I guess it could be better but my problem is not there.
declare variable $nums as xs:string external; declare variable $values as xs:string external; declare variable $time as xs:dateTime external; declare variable $site as xs:token external;
let $n := tokenize($nums,','), $v := tokenize($values,',') return for $x at $i in $n return (replace value of node /datas[@site=$site]/data[num=$x]/value with
$v[$i],
replace value of node /datas[@site=$site]/data[num=$x]/time with $time)
The problem is that sometimes it works and sometimes it gives me an
HTTP 400 error with body :
Stopped at update.xq, 9/73: [XUTY0008] Single element, text, attribute, comment or pi expected as
replace target.
I know the replace target has to have the expected format and I think
it has. I don't understand why I get this. I though it was due to too long stuff so I divided the list of datas to update into sublists of size 50. Now, the problem appears sometimes but not everytime.
When I use another XQuery script test.xq to display what was received,
everything looks ok. The test script is :
declare variable $nums as xs:string external; declare variable $values as xs:string external; declare variable $time as xs:dateTime external; declare variable $site as xs:token external; let $n := tokenize($nums,','), $v := tokenize($values,',') return for $x at $i in $n return ($x,$v[$i])
For example, this update is ok:
<?xml version="1.0"?>
<run xmlns="http://basex.org/rest"> <text>update.xq</text> <variable name="site" value="xxx"/> <variable name="time" value="2013-05-02T09:58:38"/> <variable name="nums"
value="439,375,128,426,362,243,115,413,349,230,102,400,336,272,217,153,387,259,204,76,438,374,255,127,425,361,114,412,229,101,399,335,271,216,152,386,258,203,75,11,437,373,254,126,424,360,113,411,228,100"/>
<variable name="values"
value="1515.200,408,true,973.806,3.892,false,false,0.000,0.0,6,true,430.400,false,2,327.670,true,410,true,45.410,true,0.992,408,false,false,575.060,3.545,false,0.995,87.270,false,436.800,false,94.000,45.410,false,410,false,14.135,true,true,2152.800,0,true,true,4.924,3.639,false,0.992,87.070,true"
/>
</run>
But this one is not :
<?xml version="1.0"?>
<run xmlns="http://basex.org/rest"> <text>update.xq</text> <variable name="site" value="xxx"/> <variable name="time" value="2013-05-02T09:58:38"/> <variable name="nums"
value="36,398,334,215,385,202,74,436,372,253,125,423,359,240,112,442,410,378,227,131,99,429,397,365,333,214,118,54,416,384,352,288,233,201,105,73,9,435,403,371,339,275,220,156,124,422,390,358,294,239"/>
<variable name="values"
value="true,428.400,false,45.059,410,12.710,true,2152.800,0,false,false,2.437,-0.101,false,true,4907.327,0.994,409,0.000,false,true,1012.437,448.800,0.000,false,62.260,false,true,304.600,410,0.0,58,87.249,13.180,true,true,true,2152.800,454.200,0,false,2,757,true,true,0.326,0.000,0.0,41,false"
/>
</run>
I think those documents are similar and I shouldn't see a difference.
Either it works for both of them or it doesn't.
Any idea to point me in the right direction is welcome.
Thank in advance,
Ludovic Kuty
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
Many thanks. I was focused on the "with $v[$i]" part and I forgot to check that I get a single element each time. Indeed, I have two value elements for some of them. It comes from another XML document in the DB that I used for testing purposes and completely forgot to remove.
On 02 May 2013, at 10:59, Dirk Kirsten wrote:
Dear Ludovic,
The error message indicates that the XPath /datas[@site=$site]/data[num=$x]/value return not just a single element, but multiple instead. Could it be that for some values of @site and @num you have multiple datas. This would explain why it sometimes happens and sometimes it does not. It is hard to tell as we don't have the whole xml data file, but just a snippet. Maybe you could test this and instead of updating your XML simply output /datas[@site=$site]/data[num=$x]/value You can then check if you have multiple values and then maybe you want to change your xml (if this should be invalid) or you have to change your XQuery (you could do a FLOWR expression to update all data nodes).
Cheers, Dirk
basex-talk@mailman.uni-konstanz.de