Add line-number function
Thursday, 5 July 2018 · 10 messages · last reply 16 Jul 2018
ПП
Павел Павлов5 Jul 2018 17:09 #
Quoted text · 9 lines
> >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 !
FE
Fabrice ETANCHAUD5 Jul 2018 17:49 #
As BaseX does not work on the XML textual representation, it might not be possible.
Quoted text · ????? ?????? · 25 lines
De : BaseX-Talk [mailto:basex-talk-bounces at mailman.uni-konstanz.de] De la part de ????? ?????? Envoyé : jeudi 5 juillet 2018 17:10 À : basex-talk at 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 !
CG
Christian Grün6 Jul 2018 10:24 #
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-idQuoted text · Fabrice ETANCHAUD · 49 lines
On Thu, Jul 5, 2018 at 5:49 PM Fabrice ETANCHAUD <fetanchaud at 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 at mailman.uni-konstanz.de] De la part de ????? ?????? > Envoyé : jeudi 5 juillet 2018 17:10 > À : basex-talk at 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 !
GC
Giuseppe Celano6 Jul 2018 13:37 #
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.
Quoted text · Christian Grün · 77 lines
> On Jul 6, 2018, at 10:24 AM, Christian Grün <christian.gruen at 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 at 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 at mailman.uni-konstanz.de] De la part de ????? ?????? >> Envoyé : jeudi 5 juillet 2018 17:10 >> À : basex-talk at 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 ! >
CG
Christian Grün6 Jul 2018 13:39 #
Hi Giuseppe,
Quoted text · Giuseppe Celano · 1 line
> 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,
ChristianQuoted text · Christian Grün · 80 lines
> On Jul 6, 2018, at 10:24 AM, Christian Grün <christian.gruen at 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 at 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 at mailman.uni-konstanz.de] De la part de ????? ?????? > Envoyé : jeudi 5 juillet 2018 17:10 > À : basex-talk at 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 ! > > >
GC
Giuseppe Celano6 Jul 2018 13:59 #
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}root()/Q{}nom[1]
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>Quoted text · Christian Grün · 95 lines
> On Jul 6, 2018, at 1:39 PM, Christian Grün <christian.gruen at 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 at 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 at 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 at mailman.uni-konstanz.de] De la part de ????? ?????? >> Envoyé : jeudi 5 juillet 2018 17:10 >> À : basex-talk at 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 ! >> >> >> >
CG
Christian Grün6 Jul 2018 14:32 #
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
Quoted text · Giuseppe Celano · 121 lines
On Fri, Jul 6, 2018 at 1:59 PM Giuseppe Celano <celano at 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}root()/Q{}nom[1] > > 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 at 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 at 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 at 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 at mailman.uni-konstanz.de] De la part de ????? ?????? > >> Envoyé : jeudi 5 juillet 2018 17:10 > >> À : basex-talk at 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 ! > >> > >> > >> > > >
GC
Giuseppe Celano6 Jul 2018 22:28 #
Thanks, I will experiment with this
Universität Leipzig
Institute of Computer Science, NLP
Augustusplatz 10
04109 Leipzig
Deutschland
E-mail: celano at informatik.uni-leipzig.de
E-mail: giuseppegacelano at gmail.com
Web site 1: http://www.dh.uni-leipzig.de/wo/team/
Web site 2: https://sites.google.com/site/giuseppegacelano/
Quoted text · Christian Grün · 146 lines
> On Jul 6, 2018, at 2:32 PM, Christian Grün <christian.gruen at 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 at 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}root()/Q{}nom[1] >> >> 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 at 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 at 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 at 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 at mailman.uni-konstanz.de] De la part de ????? ?????? >>>> Envoyé : jeudi 5 juillet 2018 17:10 >>>> À : basex-talk at 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?Quoted text · Christian Grün · 25 lines
>Пятница, 6 июля 2018, 15:24 +07:00 от Christian Grün <christian.gruen at 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
IL
Imsieke, Gerrit, le-tex16 Jul 2018 09:41 #
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
Quoted text · Павел Павлов · 50 lines
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 at 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 > >
--
Gerrit Imsieke
Geschäftsführer / Managing Director
le-tex publishing services GmbH
Weissenfelser Str. 84, 04229 Leipzig, Germany
Phone +49 341 355356 110, Fax +49 341 355356 510
gerrit.imsieke at le-tex.de, http://www.le-tex.de
Registergericht / Commercial Register: Amtsgericht Leipzig
Registernummer / Registration Number: HRB 24930
Geschäftsführer / Managing Directors:
Gerrit Imsieke, Svea Jelonek, Thomas Schmidt
Written for BaseX 9.0. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery