line number and column
Wednesday, 11 January 2012 · 8 messages · last reply 15 Jan 2012
AH
Anders Hessellund11 Jan 2012 23:28 #
Hi,
we are experimenting with BaseX as a database for a large set of local XML files (3000-4000). When we query for individual elements and attributes in this portfolio of XML documents, is there any way to get location information about concrete elements and attributes. Specifically, we need to know filename, line number and column of element (start tags) and attributes. Is this possible? And if so, how?
Thanks,
Anders
JE
Jens Erat11 Jan 2012 23:54 #
Hi Anders,
extracting the filename is quite easy:
//*/root()/fn:document-uri() - just change the context node to your needs. fn:document-uri(root(//*)) works, too.
I'm not totally sure about line numbers and columns, but I do not know any way to retrieve these information. If it is possible, someone else from the core team will veto soon.
Kind regards from Lake Constance, Germany,
Jens Erat--
Jens Erat
[phone]: tel:+49-151-56961126
[mail]: mailto:email at jenserat.de
[jabber]: xmpp:jabber at jenserat.de
[web]: http://www.jenserat.de
PGP: 350E D9B6 9ADC 2DED F5F2 8549 CBC2 613C D745 722B
Quoted text · Anders Hessellund · 12 lines
Am 11.01.2012 um 23:28 schrieb Anders Hessellund: > Hi, > > we are experimenting with BaseX as a database for a large set of local XML files (3000-4000). When we query for individual elements and attributes in this portfolio of XML documents, is there any way to get location information about concrete elements and attributes. Specifically, we need to know filename, line number and column of element (start tags) and attributes. Is this possible? And if so, how? > > Thanks, > > Anders > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
J
Quoted text · Anders Hessellund · 1 line
>>>>> "AH" == Anders Hessellund <anders.hessellund at gmail.com> writes:
AH> elements and attributes. Specifically, we need to know filename, line number and column of element (start tags) and AH> attributes. Is this possible? And if so, how?
Might be related http://lists.gnu.org/archive/html/bug-gnu-emacs/2011-12/msg00319.html
CG
Dear Anders,
I'm sorry: information on the original line and columns gets lost as soon as a database, or a main memory instance of a document, is created. If you look for ways to address the same XML nodes multiple times, you may want to have a look at the
fn:path(); it returns an XPath expression to the adressed nodes [1]. A simple example: for $item in doc('http://files.basex.org/xml/xmark.xml')//item
return path($item)If you have create a database from your files, you can also use the BaseX-specific
db:node-pre() and db:open-pre() functions to directly address nodes [2].
Hope this helps,
Christian
[1] http://www.w3.org/TR/xpath-functions-30/#func-path
[2] http://docs.basex.org/wiki/Database_ModuleQuoted text · Anders Hessellund · 13 lines
On Wed, Jan 11, 2012 at 11:28 PM, Anders Hessellund <anders.hessellund at gmail.com> wrote: > Hi, > > we are experimenting with BaseX as a database for a large set of local XML > files (3000-4000). When we query for individual elements and attributes in > this portfolio of XML documents, is there any way to get location > information about concrete elements and attributes. Specifically, we need to > know filename, line number and column of element (start tags) and > attributes. Is this possible? And if so, how? > > Thanks, > Anders
AH
Anders Hessellund14 Jan 2012 12:21 #
Thanks for your replies,
the line number and column info is pretty important for us. Is there perhaps some part of the parser code that I could hack/fork?
-- Anders
On Thu, Jan 12, 2012 at 11:59 AM, Christian Grün
<christian.gruen at gmail.com>wrote:
Quoted text · Christian Grün · 39 lines
> Dear Anders, > > I'm sorry: information on the original line and columns gets lost as > soon as a database, or a main memory instance of a document, is > created. If you look for ways to address the same XML nodes multiple > times, you may want to have a look at the fn:path(); it returns an > XPath expression to the adressed nodes [1]. A simple example: > > for $item in doc('http://files.basex.org/xml/xmark.xml')//item > return path($item) > > If you have create a database from your files, you can also use the > BaseX-specific db:node-pre() and db:open-pre() functions to directly > address nodes [2]. > > Hope this helps, > Christian > > [1] http://www.w3.org/TR/xpath-functions-30/#func-path > [2] http://docs.basex.org/wiki/Database_Module > ___________________________ > > On Wed, Jan 11, 2012 at 11:28 PM, Anders Hessellund > <anders.hessellund at gmail.com> wrote: > > Hi, > > > > we are experimenting with BaseX as a database for a large set of local > XML > > files (3000-4000). When we query for individual elements and attributes > in > > this portfolio of XML documents, is there any way to get location > > information about concrete elements and attributes. Specifically, we > need to > > know filename, line number and column of element (start tags) and > > attributes. Is this possible? And if so, how? > > > > Thanks, > > Anders >
CG
Christian Grün14 Jan 2012 12:37 #
Dear Anders,
maybe there's another way to achieve what you want; what do you exactly need line and column information for?
Christian
Quoted text · Anders Hessellund · 59 lines
On Sat, Jan 14, 2012 at 12:21 PM, Anders Hessellund <anders.hessellund at gmail.com> wrote: > Thanks for your replies, > > the line number and column info is pretty important for us. Is there perhaps > some part of the parser code that I could hack/fork? > > -- Anders > > > On Thu, Jan 12, 2012 at 11:59 AM, Christian Grün <christian.gruen at gmail.com> > wrote: >> >> Dear Anders, >> >> I'm sorry: information on the original line and columns gets lost as >> soon as a database, or a main memory instance of a document, is >> created. If you look for ways to address the same XML nodes multiple >> times, you may want to have a look at the fn:path(); it returns an >> XPath expression to the adressed nodes [1]. A simple example: >> >> for $item in doc('http://files.basex.org/xml/xmark.xml')//item >> return path($item) >> >> If you have create a database from your files, you can also use the >> BaseX-specific db:node-pre() and db:open-pre() functions to directly >> address nodes [2]. >> >> Hope this helps, >> Christian >> >> [1] http://www.w3.org/TR/xpath-functions-30/#func-path >> [2] http://docs.basex.org/wiki/Database_Module >> ___________________________ >> >> On Wed, Jan 11, 2012 at 11:28 PM, Anders Hessellund >> <anders.hessellund at gmail.com> wrote: >> > Hi, >> > >> > we are experimenting with BaseX as a database for a large set of local >> > XML >> > files (3000-4000). When we query for individual elements and attributes >> > in >> > this portfolio of XML documents, is there any way to get location >> > information about concrete elements and attributes. Specifically, we >> > need to >> > know filename, line number and column of element (start tags) and >> > attributes. Is this possible? And if so, how? >> > >> > Thanks, >> > Anders > > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
DG
Dave Glick14 Jan 2012 14:14 #
I had a similar requirement a while back and ended up solving it in two ways:
The first attempt I wrote a routine that would take a node and scan for all text nodes along the preceding axis. I would then add the length of each text node to a counter (I wanted offset), but counting new lines shouldn't be much different. I used the API, but I don't think it would be too tough to write an XQuery expression or function that does the same thing. Alternatively you could use the BaseX functionality to call Java code from XQuery to write it up in code.
This worked okay in isolated cases, but I needed the info very frequently (I was writing a text editor backed by XML, so I was constantly getting offsets for the caret) and scanning the preceding axis each time took too long. I ended up going through every node in sequence for a new document and caching the information. The idea was the same though - every time I hit a text node, I incremented a counter and used the value for following nodes (until I hit another text node).
Not sure if that helps - hopefully it does...
Dave
Quoted text · Christian Grün · 72 lines
-----Original message----- From: "Christian Grün" <christian.gruen at gmail.com> To: Anders Hessellund <anders.hessellund at gmail.com> Cc: "basex-talk at mailman.uni-konstanz.de" <basex-talk at mailman.uni-konstanz.de> Sent: Sat, Jan 14, 2012 11:38:06 GMT+00:00 Subject: Re: [basex-talk] line number and column Dear Anders, maybe there's another way to achieve what you want; what do you exactly need line and column information for? Christian On Sat, Jan 14, 2012 at 12:21 PM, Anders Hessellund <anders.hessellund at gmail.com> wrote: > Thanks for your replies, > > the line number and column info is pretty important for us. Is there perhaps > some part of the parser code that I could hack/fork? > > -- Anders > > > On Thu, Jan 12, 2012 at 11:59 AM, Christian Grün <christian.gruen at gmail.com> > wrote: >> >> Dear Anders, >> >> I'm sorry: information on the original line and columns gets lost as >> soon as a database, or a main memory instance of a document, is >> created. If you look for ways to address the same XML nodes multiple >> times, you may want to have a look at the fn:path(); it returns an >> XPath expression to the adressed nodes [1]. A simple example: >> >> for $item in doc('http://files.basex.org/xml/xmark.xml')//item >> return path($item) >> >> If you have create a database from your files, you can also use the >> BaseX-specific db:node-pre() and db:open-pre() functions to directly >> address nodes [2]. >> >> Hope this helps, >> Christian >> >> [1] http://www.w3.org/TR/xpath-functions-30/#func-path >> [2] http://docs.basex.org/wiki/Database_Module >> ___________________________ >> >> On Wed, Jan 11, 2012 at 11:28 PM, Anders Hessellund >> <anders.hessellund at gmail.com> wrote: >> > Hi, >> > >> > we are experimenting with BaseX as a database for a large set of local >> > XML >> > files (3000-4000). When we query for individual elements and attributes >> > in >> > this portfolio of XML documents, is there any way to get location >> > information about concrete elements and attributes. Specifically, we >> > need to >> > know filename, line number and column of element (start tags) and >> > attributes. Is this possible? And if so, how? >> > >> > Thanks, >> > Anders > > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > BaseX-Talk mailing list BaseX-Talk at mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
AH
Anders Hessellund15 Jan 2012 13:24 #
Thanks, this is very useful.
We use the line and column numbers to navigate from a XQuery to a concrete place in an XML document (in an editor). I think we will need to cache this information for each node as well.
An even better solution would have been to enrich the underlying BaseX representation with this location info.
-- Anders
Quoted text · Dave Glick · 110 lines
On Sat, Jan 14, 2012 at 1:14 PM, Dave Glick <dglick at dracorp.com> wrote: > I had a similar requirement a while back and ended up solving it in two > ways: > > The first attempt I wrote a routine that would take a node and scan for > all text nodes along the preceding axis. I would then add the length of > each text node to a counter (I wanted offset), but counting new lines > shouldn't be much different. I used the API, but I don't think it would be > too tough to write an XQuery expression or function that does the same > thing. Alternatively you could use the BaseX functionality to call Java > code from XQuery to write it up in code. > > This worked okay in isolated cases, but I needed the info very frequently > (I was writing a text editor backed by XML, so I was constantly getting > offsets for the caret) and scanning the preceding axis each time took too > long. I ended up going through every node in sequence for a new document > and caching the information. The idea was the same though - every time I > hit a text node, I incremented a counter and used the value for following > nodes (until I hit another text node). > > Not sure if that helps - hopefully it does... > > Dave > > > -----Original message----- > > *From: *"Christian Grün" <christian.gruen at gmail.com>* > To: *Anders Hessellund <anders.hessellund at gmail.com>* > Cc: *"basex-talk at mailman.uni-konstanz.de" < > basex-talk at mailman.uni-konstanz.de>* > Sent: *Sat, Jan 14, 2012 11:38:06 GMT+00:00* > Subject: *Re: [basex-talk] line number and column > > Dear Anders, > > maybe there's another way to achieve what you want; what do you > exactly need line and column information for? > > Christian > ___________________________ > > On Sat, Jan 14, 2012 at 12:21 PM, Anders Hessellund > <anders.hessellund at gmail.com> wrote: > > Thanks for your replies, > > > > the line number and column info is pretty important for us. Is there > perhaps > > some part of the parser code that I could hack/fork? > > > > -- Anders > > > > > > On Thu, Jan 12, 2012 at 11:59 AM, Christian Grün < > christian.gruen at gmail.com> > > wrote: > >> > >> Dear Anders, > >> > >> I'm sorry: information on the original line and columns gets lost as > >> soon as a database, or a main memory instance of a document, is > >> created. If you look for ways to address the same XML nodes multiple > >> times, you may want to have a look at the fn:path(); it returns an > >> XPath expression to the adressed nodes [1]. A simple example: > >> > >> for $item in doc('http://files.basex.org/xml/xmark.xml')//item > >> return path($item) > >> > >> If you have create a database from your files, you can also use the > >> BaseX-specific db:node-pre() and db:open-pre() functions to directly > >> address nodes [2]. > >> > >> Hope this helps, > >> Christian > >> > >> [1] http://www.w3.org/TR/xpath-functions-30/#func-path > >> [2] http://docs.basex.org/wiki/Database_Module > >> ___________________________ > >> > >> On Wed, Jan 11, 2012 at 11:28 PM, Anders Hessellund > >> <anders.hessellund at gmail.com> wrote: > >> > Hi, > >> > > >> > we are experimenting with BaseX as a database for a large set of local > >> > XML > >> > files (3000-4000). When we query for individual elements and > attributes > >> > in > >> > this portfolio of XML documents, is there any way to get location > >> > information about concrete elements and attributes. Specifically, we > >> > need to > >> > know filename, line number and column of element (start tags) and > >> > attributes. Is this possible? And if so, how? > >> > > >> > Thanks, > >> > Anders > > > > > > > > _______________________________________________ > > BaseX-Talk mailing list > > BaseX-Talk at mailman.uni-konstanz.de > > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > >
Written for BaseX 7.0. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery