Need help to query
Tuesday, 23 December 2014 · 5 messages
FG
Florent Gallaire23 Dec 2014 18:14 #
Hello, I need some help to query a database of thousands of xml files. They are structured only with elements with no attributes :
file1.xml
<A>
<B>
<C>value</C>
</B>
<D>
<E>text</E>
</D>
</A>
file2.xml
<A>
<B>
<C>value</C>
</B>
<D>
<E>text</E>
</D>
</A>and so on file3.xml, file4.xml....
Having the value of the <C> element, I would like to have the text of the <E> element.
What is the good query to do this ?
Best regards
Florent
--
FLOSS Engineer & Lawyer
FG
Florent Gallaire23 Dec 2014 18:16 #
The value of the <C> element is different in each file.
Quoted text · Florent Gallaire · 37 lines
On Tue, Dec 23, 2014 at 6:14 PM, Florent Gallaire <fgallaire at gmail.com> wrote: > Hello, I need some help to query a database of thousands of xml files. > They are structured only with elements with no attributes : > > file1.xml > <A> > <B> > <C>value</C> > </B> > <D> > <E>text</E> > </D> > </A> > > file2.xml > <A> > <B> > <C>value</C> > </B> > <D> > <E>text</E> > </D> > </A> > > and so on file3.xml, file4.xml.... > > Having the value of the <C> element, I would like to have the text of > the <E> element. > > What is the good query to do this ? > > Best regards > > Florent > > -- > FLOSS Engineer & Lawyer
--
FLOSS Engineer & Lawyer
DK
Dirk Kirsten23 Dec 2014 18:24 #
Hello Florent,
the query
/A/B[C = 'value']/D/E/text()
should apply the text index and should be sufficiently fast. Do you encouter any problems with this approach? As a general note you most likely always want to avoid having descendant-or-self steps (i.e. //), as it has to search the whole XML (sub)tree. So being as specific as possible in giving the path is always a good idea.
Merry BaseX-mas,
Dirk
Quoted text · Florent Gallaire · 43 lines
On 12/23/2014 06:16 PM, Florent Gallaire wrote: > The value of the <C> element is different in each file. > > On Tue, Dec 23, 2014 at 6:14 PM, Florent Gallaire <fgallaire at gmail.com> wrote: > > Hello, I need some help to query a database of thousands of xml files. > > They are structured only with elements with no attributes : > > > > file1.xml > > <A> > > <B> > > <C>value</C> > > </B> > > <D> > > <E>text</E> > > </D> > > </A> > > > > file2.xml > > <A> > > <B> > > <C>value</C> > > </B> > > <D> > > <E>text</E> > > </D> > > </A> > > > > and so on file3.xml, file4.xml.... > > > > Having the value of the <C> element, I would like to have the text of > > the <E> element. > > > > What is the good query to do this ? > > > > Best regards > > > > Florent > > > > -- > > FLOSS Engineer & Lawyer > > >
--
Dirk Kirsten, BaseX GmbH, http://basex.org
|-- Firmensitz: Blarerstrasse 56, 78462 Konstanz
|-- Registergericht Freiburg, HRB: 708285, Geschäftsführer:
| Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
CG
Christian Grün23 Dec 2014 18:26 #
Hi Florent, thanks Dirk,
Quoted text · Dirk Kirsten · 1 line
> /A/B[C = 'value']/D/E/text()
I was about to give a pretty similar answer:
/A[B/C = 'value']/D/E/text()
As B and D are on the same level, you will have to move the B step into the predicate.
Cheers,
Christian
Quoted text · Dirk Kirsten · 57 lines
> > should apply the text index and should be sufficiently fast. Do you encouter any problems with this approach? As a general note you most likely always want to avoid having descendant-or-self steps (i.e. //), as it has to search the whole XML (sub)tree. So being as specific as possible in giving the path is always a good idea. > > Merry BaseX-mas, > Dirk > > On 12/23/2014 06:16 PM, Florent Gallaire wrote: >> The value of the <C> element is different in each file. >> >> On Tue, Dec 23, 2014 at 6:14 PM, Florent Gallaire <fgallaire at gmail.com> wrote: >> > Hello, I need some help to query a database of thousands of xml files. >> > They are structured only with elements with no attributes : >> > >> > file1.xml >> > <A> >> > <B> >> > <C>value</C> >> > </B> >> > <D> >> > <E>text</E> >> > </D> >> > </A> >> > >> > file2.xml >> > <A> >> > <B> >> > <C>value</C> >> > </B> >> > <D> >> > <E>text</E> >> > </D> >> > </A> >> > >> > and so on file3.xml, file4.xml.... >> > >> > Having the value of the <C> element, I would like to have the text of >> > the <E> element. >> > >> > What is the good query to do this ? >> > >> > Best regards >> > >> > Florent >> > >> > -- >> > FLOSS Engineer & Lawyer >> >> >> > > -- > Dirk Kirsten, BaseX GmbH, http://basex.org > |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz > |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: > | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle > `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22 >
FG
Florent Gallaire23 Dec 2014 19:17 #
Thanks a lot Dirk and Christian.
The Chrisitian solution works fine for me.
BaseX is great and you too !
Merry BaseX-mas,
Florent
Quoted text · Christian Grün · 73 lines
On Tue, Dec 23, 2014 at 6:26 PM, Christian Grün <christian.gruen at gmail.com> wrote: > Hi Florent, thanks Dirk, > >> /A/B[C = 'value']/D/E/text() > > I was about to give a pretty similar answer: > > /A[B/C = 'value']/D/E/text() > > As B and D are on the same level, you will have to move the B step > into the predicate. > > Cheers, > Christian > >> >> should apply the text index and should be sufficiently fast. Do you encouter any problems with this approach? As a general note you most likely always want to avoid having descendant-or-self steps (i.e. //), as it has to search the whole XML (sub)tree. So being as specific as possible in giving the path is always a good idea. >> >> Merry BaseX-mas, >> Dirk >> >> On 12/23/2014 06:16 PM, Florent Gallaire wrote: >>> The value of the <C> element is different in each file. >>> >>> On Tue, Dec 23, 2014 at 6:14 PM, Florent Gallaire <fgallaire at gmail.com> wrote: >>> > Hello, I need some help to query a database of thousands of xml files. >>> > They are structured only with elements with no attributes : >>> > >>> > file1.xml >>> > <A> >>> > <B> >>> > <C>value</C> >>> > </B> >>> > <D> >>> > <E>text</E> >>> > </D> >>> > </A> >>> > >>> > file2.xml >>> > <A> >>> > <B> >>> > <C>value</C> >>> > </B> >>> > <D> >>> > <E>text</E> >>> > </D> >>> > </A> >>> > >>> > and so on file3.xml, file4.xml.... >>> > >>> > Having the value of the <C> element, I would like to have the text of >>> > the <E> element. >>> > >>> > What is the good query to do this ? >>> > >>> > Best regards >>> > >>> > Florent >>> > >>> > -- >>> > FLOSS Engineer & Lawyer >>> >>> >>> >> >> -- >> Dirk Kirsten, BaseX GmbH, http://basex.org >> |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz >> |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: >> | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle >> `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22 >>
--
FLOSS Engineer & Lawyer
Written for BaseX 7.9. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery