Hello, could the $err:line-number [1] variable help you ?
[1] http://docs.basex.org/wiki/XQuery_3.0#Try.2FCatch
Best regards,
Fabrice ETANCHAUD cerfrancepch
No, $err:line-number show line number of xquery file. I want this:
Example.xml -> 1: <root> 2: <child> 3: <grandchild>text1</grandchild> 4: <grandchild>text2</grandchild> 5: <grandchild>text3</grandchild> 6: <grandchild>text4</grandchild> 7: </child> 8: </root>
Xquery -> let $f := doc("example.xml") let $e := $f/root/child[1]/grandchild[3]
let $line := line-number($e)
And I want get $line = 5 !
As BaseX does not work on the XML textual representation, it might not be possible.
De : BaseX-Talk [mailto:basex-talk-bounces@mailman.uni-konstanz.de] De la part de ????? ?????? Envoyé : jeudi 5 juillet 2018 17:10 À : basex-talk@mailman.uni-konstanz.de Objet : [basex-talk] Add line-number function
Hello, could the $err:line-number [1] variable help you ?
[1] http://docs.basex.org/wiki/XQuery_3.0#Try.2FCatch
Best regards,
Fabrice ETANCHAUD cerfrancepch No, $err:line-number show line number of xquery file. I want this:
Example.xml -> 1: <root> 2: <child> 3: <grandchild>text1</grandchild> 4: <grandchild>text2</grandchild> 5: <grandchild>text3</grandchild> 6: <grandchild>text4</grandchild> 7: </child> 8: </root>
Xquery -> let $f := doc("example.xml") let $e := $f/root/child[1]/grandchild[3]
let $line := line-number($e)
And I want get $line = 5 !
Hi Symantis,
The original line numbers are not stored in XML databases (they may change after updated, and would consume additional memory), so you won’t be able to retrieve them with XQuery.
As far as I know, this does not work in eXist-db either; the eXist link you referenced gives you the line of the util:line-number expression in your XQuery module. As Fabrice pointed out (thanks!), this could also be realized with $err:line-number.
With Saxon, it works indeed. However, you’ll need you use the -l command line option (otherwise, due to performance considerations, line numbers will be discarded as well).
On query/database level, there are two ways to get a direct reference: • With fn:path, you get an XPath expression that points to your node. • With db:node-pre [1], you get a direct reference to the node in a database.
Best, Christian
[1] http://docs.basex.org/wiki/Database_Module#db:node-id
On Thu, Jul 5, 2018 at 5:49 PM Fabrice ETANCHAUD fetanchaud@pch.cerfrance.fr wrote:
As BaseX does not work on the XML textual representation, it might not be possible.
De : BaseX-Talk [mailto:basex-talk-bounces@mailman.uni-konstanz.de] De la part de ????? ?????? Envoyé : jeudi 5 juillet 2018 17:10 À : basex-talk@mailman.uni-konstanz.de Objet : [basex-talk] Add line-number function
Hello, could the $err:line-number [1] variable help you ?
[1] http://docs.basex.org/wiki/XQuery_3.0#Try.2FCatch
Best regards,
Fabrice ETANCHAUD cerfrancepch
No, $err:line-number show line number of xquery file. I want this:
Example.xml -> 1: <root> 2: <child> 3: <grandchild>text1</grandchild> 4: <grandchild>text2</grandchild> 5: <grandchild>text3</grandchild> 6: <grandchild>text4</grandchild> 7: </child> 8: </root>
Xquery -> let $f := doc("example.xml") let $e := $f/root/child[1]/grandchild[3]
let $line := line-number($e)
And I want get $line = 5 !
fn:node() returns the path to a node (including the text node): Is there a similar function to get character offsets within a text node?
I am thinking of a case where, for example, one tokenizes a text within an element and would like to get the xpath + offsets for every token.
On Jul 6, 2018, at 10:24 AM, Christian Grün christian.gruen@gmail.com wrote:
Hi Symantis,
The original line numbers are not stored in XML databases (they may change after updated, and would consume additional memory), so you won’t be able to retrieve them with XQuery.
As far as I know, this does not work in eXist-db either; the eXist link you referenced gives you the line of the util:line-number expression in your XQuery module. As Fabrice pointed out (thanks!), this could also be realized with $err:line-number.
With Saxon, it works indeed. However, you’ll need you use the -l command line option (otherwise, due to performance considerations, line numbers will be discarded as well).
On query/database level, there are two ways to get a direct reference: • With fn:path, you get an XPath expression that points to your node. • With db:node-pre [1], you get a direct reference to the node in a database.
Best, Christian
[1] http://docs.basex.org/wiki/Database_Module#db:node-id
On Thu, Jul 5, 2018 at 5:49 PM Fabrice ETANCHAUD fetanchaud@pch.cerfrance.fr wrote:
As BaseX does not work on the XML textual representation, it might not be possible.
De : BaseX-Talk [mailto:basex-talk-bounces@mailman.uni-konstanz.de] De la part de ????? ?????? Envoyé : jeudi 5 juillet 2018 17:10 À : basex-talk@mailman.uni-konstanz.de Objet : [basex-talk] Add line-number function
Hello, could the $err:line-number [1] variable help you ?
[1] http://docs.basex.org/wiki/XQuery_3.0#Try.2FCatch
Best regards,
Fabrice ETANCHAUD cerfrancepch
No, $err:line-number show line number of xquery file. I want this:
Example.xml -> 1: <root> 2: <child> 3: <grandchild>text1</grandchild> 4: <grandchild>text2</grandchild> 5: <grandchild>text3</grandchild> 6: <grandchild>text4</grandchild> 7: </child> 8: </root>
Xquery -> let $f := doc("example.xml") let $e := $f/root/child[1]/grandchild[3]
let $line := line-number($e)
And I want get $line = 5 !
Hi Giuseppe,
fn:node() returns the path to a node (including the text node): Is there a similar function to get character offsets within a text node?
I am not sure what you need. Do you talk about fn:path? What could the character offset be / do you have an example?
Grazie, Christian
On Jul 6, 2018, at 10:24 AM, Christian Grün christian.gruen@gmail.com wrote:
Hi Symantis,
The original line numbers are not stored in XML databases (they may change after updated, and would consume additional memory), so you won’t be able to retrieve them with XQuery.
As far as I know, this does not work in eXist-db either; the eXist link you referenced gives you the line of the util:line-number expression in your XQuery module. As Fabrice pointed out (thanks!), this could also be realized with $err:line-number.
With Saxon, it works indeed. However, you’ll need you use the -l command line option (otherwise, due to performance considerations, line numbers will be discarded as well).
On query/database level, there are two ways to get a direct reference: • With fn:path, you get an XPath expression that points to your node. • With db:node-pre [1], you get a direct reference to the node in a database.
Best, Christian
[1] http://docs.basex.org/wiki/Database_Module#db:node-id
On Thu, Jul 5, 2018 at 5:49 PM Fabrice ETANCHAUD fetanchaud@pch.cerfrance.fr wrote:
As BaseX does not work on the XML textual representation, it might not be possible.
De : BaseX-Talk [mailto:basex-talk-bounces@mailman.uni-konstanz.de] De la part de ????? ?????? Envoyé : jeudi 5 juillet 2018 17:10 À : basex-talk@mailman.uni-konstanz.de Objet : [basex-talk] Add line-number function
Hello, could the $err:line-number [1] variable help you ?
[1] http://docs.basex.org/wiki/XQuery_3.0#Try.2FCatch
Best regards,
Fabrice ETANCHAUD cerfrancepch
No, $err:line-number show line number of xquery file. I want this:
Example.xml -> 1: <root> 2: <child> 3: <grandchild>text1</grandchild> 4: <grandchild>text2</grandchild> 5: <grandchild>text3</grandchild> 6: <grandchild>text4</grandchild> 7: </child> 8: </root>
Xquery -> let $f := doc("example.xml") let $e := $f/root/child[1]/grandchild[3]
let $line := line-number($e)
And I want get $line = 5 !
Yes, fn:path (not fn:node)!
the following works
<fas><nom>this is an example</nom></fas>/nom/fn:path(.)
with the useful result
Q{http://www.w3.org/2005/xpath-functions%7Droot()/Q%7B%7Dnom%5B1]
but the following does not (because tokenize() does not return a node)
<fas><nom>this is an example</nom></fas>/tokenize(nom, " ")/fn:path(.)
what I was looking for is a function returning something like
<t path="Q{http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" start="0" end="3">this</t> <t path="Q{http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" start="5" end="6">is</t> <t path="Q{http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" start="8" end="9">an</t> <t path="Q{http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" start="11" end="17">example</t>
On Jul 6, 2018, at 1:39 PM, Christian Grün christian.gruen@gmail.com wrote:
Hi Giuseppe,
fn:node() returns the path to a node (including the text node): Is there a similar function to get character offsets within a text node?
I am not sure what you need. Do you talk about fn:path? What could the character offset be / do you have an example?
Grazie, Christian
On Jul 6, 2018, at 10:24 AM, Christian Grün christian.gruen@gmail.com wrote:
Hi Symantis,
The original line numbers are not stored in XML databases (they may change after updated, and would consume additional memory), so you won’t be able to retrieve them with XQuery.
As far as I know, this does not work in eXist-db either; the eXist link you referenced gives you the line of the util:line-number expression in your XQuery module. As Fabrice pointed out (thanks!), this could also be realized with $err:line-number.
With Saxon, it works indeed. However, you’ll need you use the -l command line option (otherwise, due to performance considerations, line numbers will be discarded as well).
On query/database level, there are two ways to get a direct reference: • With fn:path, you get an XPath expression that points to your node. • With db:node-pre [1], you get a direct reference to the node in a database.
Best, Christian
[1] http://docs.basex.org/wiki/Database_Module#db:node-id
On Thu, Jul 5, 2018 at 5:49 PM Fabrice ETANCHAUD fetanchaud@pch.cerfrance.fr wrote:
As BaseX does not work on the XML textual representation, it might not be possible.
De : BaseX-Talk [mailto:basex-talk-bounces@mailman.uni-konstanz.de] De la part de ????? ?????? Envoyé : jeudi 5 juillet 2018 17:10 À : basex-talk@mailman.uni-konstanz.de Objet : [basex-talk] Add line-number function
Hello, could the $err:line-number [1] variable help you ?
[1] http://docs.basex.org/wiki/XQuery_3.0#Try.2FCatch
Best regards,
Fabrice ETANCHAUD cerfrancepch
No, $err:line-number show line number of xquery file. I want this:
Example.xml -> 1: <root> 2: <child> 3: <grandchild>text1</grandchild> 4: <grandchild>text2</grandchild> 5: <grandchild>text3</grandchild> 6: <grandchild>text4</grandchild> 7: </child> 8: </root>
Xquery -> let $f := doc("example.xml") let $e := $f/root/child[1]/grandchild[3]
let $line := line-number($e)
And I want get $line = 5 !
This is definitely something you can do in XQuery itself. Just a little example, to get you started (shorter suggestions are welcome):
let $text := text { 'this is an example' } let $snippets := analyze-string($text, ' ')/* let $starts := (0, fold-left($snippets, (), function($list, $result) { let $length := string-length($result) return if(empty($list)) then ( $length ) else ( ($list, $list[last()] + $length) ) })) for $snippet at $pos in $snippets where local-name($snippet) = 'non-match' return <t start="{ $starts[$pos] }" end="{ $starts[$pos + 1] }">{ $snippet/text() }</t>
Cheers, Christian
On Fri, Jul 6, 2018 at 1:59 PM Giuseppe Celano celano@informatik.uni-leipzig.de wrote:
Yes, fn:path (not fn:node)!
the following works
<fas><nom>this is an example</nom></fas>/nom/fn:path(.)
with the useful result
Q{http://www.w3.org/2005/xpath-functions%7Droot()/Q%7B%7Dnom%5B1]
but the following does not (because tokenize() does not return a node)
<fas><nom>this is an example</nom></fas>/tokenize(nom, " ")/fn:path(.)
what I was looking for is a function returning something like
<t path="Q{http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" start="0" end="3">this</t> <t path="Q{http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" start="5" end="6">is</t> <t path="Q{http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" start="8" end="9">an</t> <t path="Q{http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" start="11" end="17">example</t>
On Jul 6, 2018, at 1:39 PM, Christian Grün christian.gruen@gmail.com wrote:
Hi Giuseppe,
fn:node() returns the path to a node (including the text node): Is there a similar function to get character offsets within a text node?
I am not sure what you need. Do you talk about fn:path? What could the character offset be / do you have an example?
Grazie, Christian
On Jul 6, 2018, at 10:24 AM, Christian Grün christian.gruen@gmail.com wrote:
Hi Symantis,
The original line numbers are not stored in XML databases (they may change after updated, and would consume additional memory), so you won’t be able to retrieve them with XQuery.
As far as I know, this does not work in eXist-db either; the eXist link you referenced gives you the line of the util:line-number expression in your XQuery module. As Fabrice pointed out (thanks!), this could also be realized with $err:line-number.
With Saxon, it works indeed. However, you’ll need you use the -l command line option (otherwise, due to performance considerations, line numbers will be discarded as well).
On query/database level, there are two ways to get a direct reference: • With fn:path, you get an XPath expression that points to your node. • With db:node-pre [1], you get a direct reference to the node in a database.
Best, Christian
[1] http://docs.basex.org/wiki/Database_Module#db:node-id
On Thu, Jul 5, 2018 at 5:49 PM Fabrice ETANCHAUD fetanchaud@pch.cerfrance.fr wrote:
As BaseX does not work on the XML textual representation, it might not be possible.
De : BaseX-Talk [mailto:basex-talk-bounces@mailman.uni-konstanz.de] De la part de ????? ?????? Envoyé : jeudi 5 juillet 2018 17:10 À : basex-talk@mailman.uni-konstanz.de Objet : [basex-talk] Add line-number function
Hello, could the $err:line-number [1] variable help you ?
[1] http://docs.basex.org/wiki/XQuery_3.0#Try.2FCatch
Best regards,
Fabrice ETANCHAUD cerfrancepch
No, $err:line-number show line number of xquery file. I want this:
Example.xml -> 1: <root> 2: <child> 3: <grandchild>text1</grandchild> 4: <grandchild>text2</grandchild> 5: <grandchild>text3</grandchild> 6: <grandchild>text4</grandchild> 7: </child> 8: </root>
Xquery -> let $f := doc("example.xml") let $e := $f/root/child[1]/grandchild[3]
let $line := line-number($e)
And I want get $line = 5 !
Thanks, I will experiment with this
Universität Leipzig Institute of Computer Science, NLP Augustusplatz 10 04109 Leipzig Deutschland E-mail: celano@informatik.uni-leipzig.de E-mail: giuseppegacelano@gmail.com Web site 1: http://www.dh.uni-leipzig.de/wo/team/ Web site 2: https://sites.google.com/site/giuseppegacelano/
On Jul 6, 2018, at 2:32 PM, Christian Grün christian.gruen@gmail.com wrote:
This is definitely something you can do in XQuery itself. Just a little example, to get you started (shorter suggestions are welcome):
let $text := text { 'this is an example' } let $snippets := analyze-string($text, ' ')/* let $starts := (0, fold-left($snippets, (), function($list, $result) { let $length := string-length($result) return if(empty($list)) then ( $length ) else ( ($list, $list[last()] + $length) ) })) for $snippet at $pos in $snippets where local-name($snippet) = 'non-match' return <t start="{ $starts[$pos] }" end="{ $starts[$pos + 1] }">{ $snippet/text() }</t>
Cheers, Christian
On Fri, Jul 6, 2018 at 1:59 PM Giuseppe Celano celano@informatik.uni-leipzig.de wrote:
Yes, fn:path (not fn:node)!
the following works
<fas><nom>this is an example</nom></fas>/nom/fn:path(.)
with the useful result
Q{http://www.w3.org/2005/xpath-functions%7Droot()/Q%7B%7Dnom%5B1]
but the following does not (because tokenize() does not return a node)
<fas><nom>this is an example</nom></fas>/tokenize(nom, " ")/fn:path(.)
what I was looking for is a function returning something like
<t path="Q{http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" start="0" end="3">this</t> <t path="Q{http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" start="5" end="6">is</t> <t path="Q{http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" start="8" end="9">an</t> <t path="Q{http://www.w3.org/2005/xpath-functions}root()/Q{}nom[1]" start="11" end="17">example</t>
On Jul 6, 2018, at 1:39 PM, Christian Grün christian.gruen@gmail.com wrote:
Hi Giuseppe,
fn:node() returns the path to a node (including the text node): Is there a similar function to get character offsets within a text node?
I am not sure what you need. Do you talk about fn:path? What could the character offset be / do you have an example?
Grazie, Christian
On Jul 6, 2018, at 10:24 AM, Christian Grün christian.gruen@gmail.com wrote:
Hi Symantis,
The original line numbers are not stored in XML databases (they may change after updated, and would consume additional memory), so you won’t be able to retrieve them with XQuery.
As far as I know, this does not work in eXist-db either; the eXist link you referenced gives you the line of the util:line-number expression in your XQuery module. As Fabrice pointed out (thanks!), this could also be realized with $err:line-number.
With Saxon, it works indeed. However, you’ll need you use the -l command line option (otherwise, due to performance considerations, line numbers will be discarded as well).
On query/database level, there are two ways to get a direct reference: • With fn:path, you get an XPath expression that points to your node. • With db:node-pre [1], you get a direct reference to the node in a database.
Best, Christian
[1] http://docs.basex.org/wiki/Database_Module#db:node-id
On Thu, Jul 5, 2018 at 5:49 PM Fabrice ETANCHAUD fetanchaud@pch.cerfrance.fr wrote:
As BaseX does not work on the XML textual representation, it might not be possible.
De : BaseX-Talk [mailto:basex-talk-bounces@mailman.uni-konstanz.de] De la part de ????? ?????? Envoyé : jeudi 5 juillet 2018 17:10 À : basex-talk@mailman.uni-konstanz.de Objet : [basex-talk] Add line-number function
Hello, could the $err:line-number [1] variable help you ?
[1] http://docs.basex.org/wiki/XQuery_3.0#Try.2FCatch
Best regards,
Fabrice ETANCHAUD cerfrancepch
No, $err:line-number show line number of xquery file. I want this:
Example.xml -> 1: <root> 2: <child> 3: <grandchild>text1</grandchild> 4: <grandchild>text2</grandchild> 5: <grandchild>text3</grandchild> 6: <grandchild>text4</grandchild> 7: </child> 8: </root>
Xquery -> let $f := doc("example.xml") let $e := $f/root/child[1]/grandchild[3]
let $line := line-number($e)
And I want get $line = 5 !
Thanks for the detailed answer.
Our software is developed in .NET. And we use BaseX as a Xquery processor. We use fn:path and return path to error element to user. But it's not enough. Our users are ordinary people, not IT, and they want to see in which lines of xml files there are mistakes. Now after execution of xquery by BaseX our application load xml file (in memory to XDocument object from .NET XML) with specified flag SetLineInfo. Then we execute returned xpath to select node in loaded xml file and get line number of selected node. Then we return line number to user. That is, we have to load the file by .NET only to get the line number. If BaseX could do it itself we wouldn't have to load xml file at all. It would be a great benefit for us.
Is it possible to add some _mode_ in BaseX to store line numbers even with additional memory and undefined line numbers on changed or updated xml nodes?
Пятница, 6 июля 2018, 15:24 +07:00 от Christian Grün christian.gruen@gmail.com:
Hi Symantis,
The original line numbers are not stored in XML databases (they may change after updated, and would consume additional memory), so you won’t be able to retrieve them with XQuery.
As far as I know, this does not work in eXist-db either; the eXist link you referenced gives you the line of the util:line-number expression in your XQuery module. As Fabrice pointed out (thanks!), this could also be realized with $err:line-number.
With Saxon, it works indeed. However, you’ll need you use the -l command line option (otherwise, due to performance considerations, line numbers will be discarded as well).
On query/database level, there are two ways to get a direct reference: • With fn:path, you get an XPath expression that points to your node. • With db:node-pre [1], you get a direct reference to the node in a database.
Best, Christian
Hi Pavel,
What kind of editor are your users using? If they use an XML editor proper, there will probably be a means to jump to a location specified by an XPath expression.
If they are using an ordinary text editor, how do you prevent them from messing up the XML in the first place? Ordinary, non-IT users tend to render XML moot if left without appropriate tooling.
If you are a visual editor that hides the tags, it should be easier to insert error feedback by XPath location than by line number.
Maybe you want to create an HTML rendering of the input where you highlight the errors (using their XPath locations). Then the users have enough context to locate the erroneous piece in the original XML input.
I’m just thinking of workarounds since I assume that the notion of line numbers is not something that can easily be added to the BaseX storage layout. As someone who often deals with non-indented XML files that consist of a single line or with XML that is formatted&indented with varying line lengths, I have come to avoid relying on line number information altogether.
Gerrit
On 16.07.2018 08:45, Павел Павлов wrote:
Thanks for the detailed answer.
Our software is developed in .NET. And we use BaseX as a Xquery processor. We use fn:path and return path to error element to user. But it's not enough. Our users are ordinary people, not IT, and they want to see in which lines of xml files there are mistakes. Now after execution of xquery by BaseX our application load xml file (in memory to XDocument object from .NET XML) with specified flag SetLineInfo. Then we execute returned xpath to select node in loaded xml file and get line number of selected node. Then we return line number to user. That is, we have to load the file by .NET only to get the line number. If BaseX could do it itself we wouldn't have to load xml file at all. It would be a great benefit for us.
Is it possible to add some _mode_ in BaseX to store line numbers even with additional memory and undefined line numbers on changed or updated xml nodes?
Пятница, 6 июля 2018, 15:24 +07:00 от Christian Grün <christian.gruen@gmail.com>: Hi Symantis, The original line numbers are not stored in XML databases (they may change after updated, and would consume additional memory), so you won’t be able to retrieve them with XQuery. As far as I know, this does not work in eXist-db either; the eXist link you referenced gives you the line of the util:line-number expression in your XQuery module. As Fabrice pointed out (thanks!), this could also be realized with $err:line-number. With Saxon, it works indeed. However, you’ll need you use the -l command line option (otherwise, due to performance considerations, line numbers will be discarded as well). On query/database level, there are two ways to get a direct reference: • With fn:path, you get an XPath expression that points to your node. • With db:node-pre [1], you get a direct reference to the node in a database. Best, Christian [1] http://docs.basex.org/wiki/Database_Module#db:node-id
basex-talk@mailman.uni-konstanz.de