Discussion:
[xquery-talk] Can XQuery Update corrupt documents?
Joe Wicentowski
2016-06-09 22:53:08 UTC
Permalink
Hi all,

I'm struggling with an XQuery Update problem which is corrupting the file
I'm trying to update. I've posted my code samples to
https://gist.github.com/joewiz/2369367de3babba30e0aad8c9beec893 - but
here's the core of the issue:

I'm working with a TEI document containing <ref> elements that I'm trying
to manipulate with XQuery Update. Specifically, I'm grabbing a page number
reference from the text node immediately following the <ref> element, and I
want to move the page number inside the <ref> element. (I'm actually trying
to do a few more things, but I've reduced the sample code to do just this,
because it illustrates the problem I'm facing.)

The problem is that the XQuery Update statement corrupts my file. The
resulting file has 0 bytes. When I comment out the XQuery Update statement
and uncomment the $test variable in the return expression, I get expected
results, so I think the logic is sound. I have a feeling that the problem
may have to do with line 25, where I add attributes to an element; when I
comment out this, the corruption doesn't occur. But I need the attributes
in that line. So I'm stumped. I've never encountered data corruption with
XQuery Update, so I really hope there's a solution.

I'm using Saxon-EE XQuery 9.6.0.7 inside of oXygen 17.1, with Saxon's
options for XQuery 3.0 and XQuery Update enabled.

Many thanks for any suggestions,
Joe
Ghislain Fourny
2016-06-10 08:01:43 UTC
Permalink
Hi Joe,

I'm not sure what's happening with the write-back, but looking at your
code, it seems that the reconstruct function is not needed.

Indeed, when you write, say:

replace node $ref with $new-ref

A copy of $new-ref is always made (this the semantics of XQuery Update),
which is what is inserted. So even if $new-ref points to a node in the
original document, this alone can't lead to an error.

The same goes line 43: a copy is made, that's two in total.

From what I see, an insert-as-last into the ref element would be sufficient.

I hope it helps!

Kind regards,
Ghislain
Post by Joe Wicentowski
Hi all,
I'm struggling with an XQuery Update problem which is corrupting the file
I'm trying to update. I've posted my code samples to
https://gist.github.com/joewiz/2369367de3babba30e0aad8c9beec893 - but
Post by Joe Wicentowski
I'm working with a TEI document containing <ref> elements that I'm trying
to manipulate with XQuery Update. Specifically, I'm grabbing a page number
reference from the text node immediately following the <ref> element, and I
want to move the page number inside the <ref> element. (I'm actually trying
to do a few more things, but I've reduced the sample code to do just this,
because it illustrates the problem I'm facing.)
Post by Joe Wicentowski
The problem is that the XQuery Update statement corrupts my file. The
resulting file has 0 bytes. When I comment out the XQuery Update statement
and uncomment the $test variable in the return expression, I get expected
results, so I think the logic is sound. I have a feeling that the problem
may have to do with line 25, where I add attributes to an element; when I
comment out this, the corruption doesn't occur. But I need the attributes
in that line. So I'm stumped. I've never encountered data corruption with
XQuery Update, so I really hope there's a solution.
Post by Joe Wicentowski
I'm using Saxon-EE XQuery 9.6.0.7 inside of oXygen 17.1, with Saxon's
options for XQuery 3.0 and XQuery Update enabled.
Post by Joe Wicentowski
Many thanks for any suggestions,
Joe
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Michael Kay
2016-06-10 08:10:33 UTC
Permalink
I'm not sure what options oXygen sets when it invokes Saxon's XQuery Update. By default the result of doing an update in Saxon doesn't overwrite the original file, but that's configurable depending on how it's invoked.

I'll take a look at it outside the oXygen environment and see if I can tell what's going on.

XQuery Update has been rather neglected of late, both as a spec and in the Saxon implementation. We don't get much feedback on it and it doesn't get tested as thoroughly as some other parts of the code, especially in terms of the various APIs.

As a general point, this is a product issue rather than a language issue, and with product issues it's generally better to go to a product-specific forum. In the case of Saxon that's saxonica.plan.io.

Michael Kay
Saxonica
Post by Joe Wicentowski
Hi all,
I'm working with a TEI document containing <ref> elements that I'm trying to manipulate with XQuery Update. Specifically, I'm grabbing a page number reference from the text node immediately following the <ref> element, and I want to move the page number inside the <ref> element. (I'm actually trying to do a few more things, but I've reduced the sample code to do just this, because it illustrates the problem I'm facing.)
The problem is that the XQuery Update statement corrupts my file. The resulting file has 0 bytes. When I comment out the XQuery Update statement and uncomment the $test variable in the return expression, I get expected results, so I think the logic is sound. I have a feeling that the problem may have to do with line 25, where I add attributes to an element; when I comment out this, the corruption doesn't occur. But I need the attributes in that line. So I'm stumped. I've never encountered data corruption with XQuery Update, so I really hope there's a solution.
I'm using Saxon-EE XQuery 9.6.0.7 inside of oXygen 17.1, with Saxon's options for XQuery 3.0 and XQuery Update enabled.
Many thanks for any suggestions,
Joe
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Michael Kay
2016-06-10 08:39:58 UTC
Permalink
I've logged this as a Saxon issue here:

https://saxonica.plan.io/issues/2789

and you can track progress on it there by registering and doing a "watch" (the icon for that in Redmine is a five-pointed star, as anyone would guess).

I'm afraid my first attempts threw up several different symptoms which may or may not turn out to be relevant to the problem that you experienced. As I mentioned, XQuery Update doesn't get exercised very much except for running the limited W3C test suite and a very small batch of unit tests when we make a release.

Michael Kay
Saxonica
Post by Joe Wicentowski
Hi all,
I'm working with a TEI document containing <ref> elements that I'm trying to manipulate with XQuery Update. Specifically, I'm grabbing a page number reference from the text node immediately following the <ref> element, and I want to move the page number inside the <ref> element. (I'm actually trying to do a few more things, but I've reduced the sample code to do just this, because it illustrates the problem I'm facing.)
The problem is that the XQuery Update statement corrupts my file. The resulting file has 0 bytes. When I comment out the XQuery Update statement and uncomment the $test variable in the return expression, I get expected results, so I think the logic is sound. I have a feeling that the problem may have to do with line 25, where I add attributes to an element; when I comment out this, the corruption doesn't occur. But I need the attributes in that line. So I'm stumped. I've never encountered data corruption with XQuery Update, so I really hope there's a solution.
I'm using Saxon-EE XQuery 9.6.0.7 inside of oXygen 17.1, with Saxon's options for XQuery 3.0 and XQuery Update enabled.
Many thanks for any suggestions,
Joe
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Ghislain Fourny
2016-06-10 08:49:14 UTC
Permalink
Hi Joe,

I agree with Mike. Also, I noticed that you are declaring your program as
XQuery 3.0. As far as I know, the XQuery Update 3.0 specification is still
a Working Draft ( https://www.w3.org/TR/xquery-update-30/ ). I would advise
proceeding with care if you combine new XQuery 3.0 constructs with updates.

Kind regards,
Ghislain
Post by Michael Kay
https://saxonica.plan.io/issues/2789
and you can track progress on it there by registering and doing a "watch"
(the icon for that in Redmine is a five-pointed star, as anyone would
guess).
I'm afraid my first attempts threw up several different symptoms which may
or may not turn out to be relevant to the problem that you experienced. As
I mentioned, XQuery Update doesn't get exercised very much except for
running the limited W3C test suite and a very small batch of unit tests
when we make a release.
Michael Kay
Saxonica
Hi all,
I'm struggling with an XQuery Update problem which is corrupting the file
I'm trying to update. I've posted my code samples to
https://gist.github.com/joewiz/2369367de3babba30e0aad8c9beec893 - but
I'm working with a TEI document containing <ref> elements that I'm trying
to manipulate with XQuery Update. Specifically, I'm grabbing a page number
reference from the text node immediately following the <ref> element, and I
want to move the page number inside the <ref> element. (I'm actually trying
to do a few more things, but I've reduced the sample code to do just this,
because it illustrates the problem I'm facing.)
The problem is that the XQuery Update statement corrupts my file. The
resulting file has 0 bytes. When I comment out the XQuery Update statement
and uncomment the $test variable in the return expression, I get expected
results, so I think the logic is sound. I have a feeling that the problem
may have to do with line 25, where I add attributes to an element; when I
comment out this, the corruption doesn't occur. But I need the attributes
in that line. So I'm stumped. I've never encountered data corruption with
XQuery Update, so I really hope there's a solution.
I'm using Saxon-EE XQuery 9.6.0.7 inside of oXygen 17.1, with Saxon's
options for XQuery 3.0 and XQuery Update enabled.
Many thanks for any suggestions,
Joe
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Joe Wicentowski
2016-06-10 19:54:18 UTC
Permalink
Hi Ghislain and Mike,

Thank you for your replies, and thanks especially to Mike for tracking down
the source of the problem I was having. As indicated at
https://saxonica.plan.io/issues/2789, a forthcoming maintenance release of
Saxon will incorporate the fix.

In the meantime, I have a workaround - which has its own drawbacks.
Perhaps this is a pure XQuery question, and isn't Saxon-specific. Here's
the problem: If I remove the local:reconstruct() function, the XQuery
Update operation works just fine, but all of the resulting interior nodes
have an additional unwanted in-scope namespace declaration - see what
happens to the source after transformation:

Source:
<note xmlns="http://www.tei-c.org/ns/1.0" xmlns:frus="
http://history.state.gov/frus/ns/1.0">
For text of NSC 164/1, see
<ref>
<hi rend="italic">Foreign Relations,</hi>
1952–1954, vol. VII, Part 2
</ref>, p. 1914.
</note>

After transformation:
<note xmlns="http://www.tei-c.org/ns/1.0" xmlns:frus="
http://history.state.gov/frus/ns/1.0">
For text of NSC 164/1, see
<ref>
<hi xmlns:frus="http://history.state.gov/frus/ns/1.0"
rend="italic">Foreign Relations,</hi>
1952–1954, vol. VII, Part 2, p. 1914
</ref>.
</note>

See the `xmlns:frus="http://history.state.gov/frus/ns/1.0"` bit? This
namespace is in scope for the whole document, so I don't want it to
reappear each time I This didn't appear when I used local:reconstruct(). I
couldn't figure out any way to suppress this from appearing, except my
local:reconstruct() function, which triggered the Saxon bug. I can clean
this extra namespace declaration up via find and replace, but it would be
ideal not to have to do this.

Is there a way to suppress the declaration of in-scope namespaces in the
result? I've posted a new gist with the updated code to demonstrate the
issue: https://gist.github.com/joewiz/6092b1181cd53d9a5378aed369387bff.

Thanks,
Joe
Post by Ghislain Fourny
Hi Joe,
I agree with Mike. Also, I noticed that you are declaring your program as
XQuery 3.0. As far as I know, the XQuery Update 3.0 specification is still
a Working Draft ( https://www.w3.org/TR/xquery-update-30/ ). I would
advise proceeding with care if you combine new XQuery 3.0 constructs with
updates.
Kind regards,
Ghislain
Post by Michael Kay
https://saxonica.plan.io/issues/2789
and you can track progress on it there by registering and doing a "watch"
(the icon for that in Redmine is a five-pointed star, as anyone would
guess).
I'm afraid my first attempts threw up several different symptoms which
may or may not turn out to be relevant to the problem that you experienced.
As I mentioned, XQuery Update doesn't get exercised very much except for
running the limited W3C test suite and a very small batch of unit tests
when we make a release.
Michael Kay
Saxonica
Hi all,
I'm struggling with an XQuery Update problem which is corrupting the file
I'm trying to update. I've posted my code samples to
https://gist.github.com/joewiz/2369367de3babba30e0aad8c9beec893 - but
I'm working with a TEI document containing <ref> elements that I'm trying
to manipulate with XQuery Update. Specifically, I'm grabbing a page number
reference from the text node immediately following the <ref> element, and I
want to move the page number inside the <ref> element. (I'm actually trying
to do a few more things, but I've reduced the sample code to do just this,
because it illustrates the problem I'm facing.)
The problem is that the XQuery Update statement corrupts my file. The
resulting file has 0 bytes. When I comment out the XQuery Update statement
and uncomment the $test variable in the return expression, I get expected
results, so I think the logic is sound. I have a feeling that the problem
may have to do with line 25, where I add attributes to an element; when I
comment out this, the corruption doesn't occur. But I need the attributes
in that line. So I'm stumped. I've never encountered data corruption with
XQuery Update, so I really hope there's a solution.
I'm using Saxon-EE XQuery 9.6.0.7 inside of oXygen 17.1, with Saxon's
options for XQuery 3.0 and XQuery Update enabled.
Many thanks for any suggestions,
Joe
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Loading...