Problem with RunQueries.java example!!

Saturday, 7 July 2012 · 9 messages · last reply 9 Jul 2012
AA
Anand Chiney (AIR)7 Jul 2012 10:45 #
Dear BaseX Team, The method iterate() which is used to convert the XML result to its Java representation is retuning [null]. I tried this code with the default query and also with 2-3 more XML files. All are giving same, [null] output..!! Have a nice day :) Regards Anand Chiney
CG
Christian Grün7 Jul 2012 12:18 #
Hi Anand, please provide us with some more concise information to improve chances that we can help you. We have one RunQueries.java class, but its iterate() function... https://github.com/BaseXdb/basex-examples/blob/master/src/main/java/org/basex/examples/query/RunQueries.java#L113 ...is not supposed to return any values. Best, Christian
Quoted text · Anand Chiney (AIR) · 30 lines
> The method iterate() which is used to convert the XML result to its Java > representation is retuning [null]. > > I tried this code with the default query and also with 2-3 more XML files. > All are giving same, [null] output..!! > > > > > > > > > > Have a nice day :) > > > > Regards > > Anand Chiney > > > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
SY
Sandeep Yohans7 Jul 2012 13:02 #
Hello Christian, We are extracting names from a very long list of names. The item.toJava() method call in iterate(query) is returning null. example output: [li: null] Rest of the methods are printing output fine.
-- Thanks and Regards Sandeep Yohans Software Developer Systems - AIR Infotech Nagpur - India www.airinfotech.in Mobile: +91-997-086-5520
CG
Christian Grün7 Jul 2012 13:04 #
One again I'm sorry… Please send us a (small !) example that we can try by ourselves. Thank you in advance, Christian
Quoted text · Sandeep Yohans · 22 lines
On Sat, Jul 7, 2012 at 1:02 PM, Sandeep Yohans <sandeepy.air at gmail.com> wrote: > Hello Christian, > > We are extracting names from a very long list of names. The item.toJava() > method call in iterate(query) is returning null. > example output: > > [li: null] > > Rest of the methods are printing output fine. > > > -- > Thanks and Regards > > Sandeep Yohans > Software Developer > Systems - AIR Infotech > Nagpur - India > www.airinfotech.in > Mobile: +91-997-086-5520 >
CG
Christian Grün7 Jul 2012 13:26 #
Your query will yield the expected results if you remove the explicit cq.execute(); call. In the latest snapshot [1], an exception will be returned if the result has already been requested. Hope this helps, Christian [1] http://files.basex.org/releases/latest/
Quoted text · Christian Grün · 50 lines
> Dear Christian > > Please find attached 2 files, MyRunQueries.java and input.xml > > The .java file is an edited version of RunQueries.java version and the > > I hope this would be sufficient for you to test. > > > > Regards > Anand chiney > > -----Original Message----- > From: Christian Grün [mailto:christian.gruen at gmail.com] > Sent: Saturday, July 07, 2012 4:34 PM > To: Sandeep Yohans > Cc: Anand Chiney; basex-talk at mailman.uni-konstanz.de > Subject: Re: Problem with RunQueries.java example!! > > One again I'm sorry… Please send us a (small !) example that we can > try by ourselves. > > Thank you in advance, > Christian > ___________________________ > > On Sat, Jul 7, 2012 at 1:02 PM, Sandeep Yohans <sandeepy.air at gmail.com> > wrote: >> Hello Christian, >> >> We are extracting names from a very long list of names. The item.toJava() >> method call in iterate(query) is returning null. >> example output: >> >> [li: null] >> >> Rest of the methods are printing output fine. >> >> >> -- >> Thanks and Regards >> >> Sandeep Yohans >> Software Developer >> Systems - AIR Infotech >> Nagpur - India >> www.airinfotech.in >> Mobile: +91-997-086-5520 >>
CG
Christian Grün7 Jul 2012 13:32 #
Here's a second feedback (sorry for being distracted): Your query does return standard Java DOM elements, the toString() method of which returns "[li: null]". As you are probably interested in the string representation of the elements, you'll need to replace "toJava()" with "serialize()": System.out.println(item.serialize()); Hope this helps, Christian
Quoted text · Christian Grün · 64 lines
On Sat, Jul 7, 2012 at 1:26 PM, Christian Grün <christian.gruen at gmail.com> wrote: > Your query will yield the expected results if you remove the explicit > cq.execute(); call. > > In the latest snapshot [1], an exception will be returned if the > result has already been requested. > > Hope this helps, > Christian > > [1] http://files.basex.org/releases/latest/ > ___________________________ > >> Dear Christian >> >> Please find attached 2 files, MyRunQueries.java and input.xml >> >> The .java file is an edited version of RunQueries.java version and the >> >> I hope this would be sufficient for you to test. >> >> >> >> Regards >> Anand chiney >> >> -----Original Message----- >> From: Christian Grün [mailto:christian.gruen at gmail.com] >> Sent: Saturday, July 07, 2012 4:34 PM >> To: Sandeep Yohans >> Cc: Anand Chiney; basex-talk at mailman.uni-konstanz.de >> Subject: Re: Problem with RunQueries.java example!! >> >> One again I'm sorry… Please send us a (small !) example that we can >> try by ourselves. >> >> Thank you in advance, >> Christian >> ___________________________ >> >> On Sat, Jul 7, 2012 at 1:02 PM, Sandeep Yohans <sandeepy.air at gmail.com> >> wrote: >>> Hello Christian, >>> >>> We are extracting names from a very long list of names. The item.toJava() >>> method call in iterate(query) is returning null. >>> example output: >>> >>> [li: null] >>> >>> Rest of the methods are printing output fine. >>> >>> >>> -- >>> Thanks and Regards >>> >>> Sandeep Yohans >>> Software Developer >>> Systems - AIR Infotech >>> Nagpur - India >>> www.airinfotech.in >>> Mobile: +91-997-086-5520 >>>
CG
Christian Grün7 Jul 2012 14:11 #
Dear Anand,
Quoted text · Christian Grün · 3 lines
> Thanks for the reply. The serialize() did work. But what I was expecting > Is pure textual output and I am getting XML output. The output which I am > getting is -
I strongly recommend you to spend some more time to get into XPath and XQuery, as those issues can all be realized fairly easily with the languages themselves. Some straightforward tutorials are e.g. found at [1,2]. Here are some examples (among many others) how you could rewrite your query to get the desired results:
  for $x in doc('input.xml')//li return $x/text()
  doc('input.xml')//li/text()
  doc('input.xml')//li/string()
  doc('input.xml')//li/data()
You can also compose the whole combobox within XQuery. Your query could then look like…
  <select>{
    for $x in doc('input.xml')//li
    return <option>{ $x/text() }</option>
  }</select>
…or…
  element select {
    doc('input.xml')//li ! element option { text() }
  }
Quoted text · Christian Grün · 110 lines
> > ----------------------------------------------------------- > * Convert each result to its Java representation: > Iterator > <li>Exercise 1</li> > <li>Exercise 2</li> > ----------------------------------------------------------- > > But I am expecting this is - > > Exercise 1 > Exercise 2 > > Actually I want to populate a JComboBox which is a part of my front-end. > So I thought that this piece of code, where it is said "Java > representation", would gimme the output as I required. > > Can you help me a little more..? > Which method will gimme the plain output, without the XML Tags...? So that > I can populate a JComboBox... !! > > > Regards, > Anand Chiney > > > -----Original Message----- > From: Christian Grün [mailto:christian.gruen at gmail.com] > Sent: Saturday, July 07, 2012 5:02 PM > To: Anand Chiney (AIR); BaseX > Subject: Re: Problem with RunQueries.java example!! > > Here's a second feedback (sorry for being distracted): Your query does > return standard Java DOM elements, the toString() method of which > returns "[li: null]". As you are probably interested in the string > representation of the elements, you'll need to replace "toJava()" with > "serialize()": > > System.out.println(item.serialize()); > > Hope this helps, > Christian > ___________________________ > > On Sat, Jul 7, 2012 at 1:26 PM, Christian Grün > <christian.gruen at gmail.com> wrote: >> Your query will yield the expected results if you remove the explicit >> cq.execute(); call. >> >> In the latest snapshot [1], an exception will be returned if the >> result has already been requested. >> >> Hope this helps, >> Christian >> >> [1] http://files.basex.org/releases/latest/ >> ___________________________ >> >>> Dear Christian >>> >>> Please find attached 2 files, MyRunQueries.java and input.xml >>> >>> The .java file is an edited version of RunQueries.java version and the >>> >>> I hope this would be sufficient for you to test. >>> >>> >>> >>> Regards >>> Anand chiney >>> >>> -----Original Message----- >>> From: Christian Grün [mailto:christian.gruen at gmail.com] >>> Sent: Saturday, July 07, 2012 4:34 PM >>> To: Sandeep Yohans >>> Cc: Anand Chiney; basex-talk at mailman.uni-konstanz.de >>> Subject: Re: Problem with RunQueries.java example!! >>> >>> One again I'm sorry… Please send us a (small !) example that we can >>> try by ourselves. >>> >>> Thank you in advance, >>> Christian >>> ___________________________ >>> >>> On Sat, Jul 7, 2012 at 1:02 PM, Sandeep Yohans <sandeepy.air at gmail.com> >>> wrote: >>>> Hello Christian, >>>> >>>> We are extracting names from a very long list of names. The > item.toJava() >>>> method call in iterate(query) is returning null. >>>> example output: >>>> >>>> [li: null] >>>> >>>> Rest of the methods are printing output fine. >>>> >>>> >>>> -- >>>> Thanks and Regards >>>> >>>> Sandeep Yohans >>>> Software Developer >>>> Systems - AIR Infotech >>>> Nagpur - India >>>> www.airinfotech.in >>>> Mobile: +91-997-086-5520 >>>> >
AA
Anand Chiney (AIR)9 Jul 2012 10:55 #
Dear BaseX Team, The below code is working fine and I am getting the required output -
  for $x in doc('input.xml')//li return $x/text()
i.e; ------------------------Output with XML File---------------- Example 1 Example 2 Example 3 ------------------------------------------------------------ But when I try the same with BaseX DB , I am not getting the required output ;-(
    for $x in doc('input')//li return $x/text()
------------------------Output with DB---------------------- Example 1Example 2Example 3 ------------------------------------------------------------ Now the first output can easily be populated in the Combo box, but what about the second..? The length of the output is not fixed in real application... I have attached the input.xml file. Regards, Anand Chiney
Quoted text · Christian Grün · 143 lines
-----Original Message----- From: Christian Grün [mailto:christian.gruen at gmail.com] Sent: Saturday, July 07, 2012 5:42 PM To: Anand Chiney (AIR); BaseX Subject: Re: Problem with RunQueries.java example!! Dear Anand, > Thanks for the reply. The serialize() did work. But what I was expecting > Is pure textual output and I am getting XML output. The output which I am > getting is - I strongly recommend you to spend some more time to get into XPath and XQuery, as those issues can all be realized fairly easily with the languages themselves. Some straightforward tutorials are e.g. found at [1,2]. Here are some examples (among many others) how you could rewrite your query to get the desired results: for $x in doc('input.xml')//li return $x/text() doc('input.xml')//li/text() doc('input.xml')//li/string() doc('input.xml')//li/data() You can also compose the whole combobox within XQuery. Your query could then look like <select>{ for $x in doc('input.xml')//li return <option>{ $x/text() }</option> }</select> or element select { doc('input.xml')//li ! element option { text() } } Hope this helps, Christian [1] http://www.w3schools.com/xpath [2] http://www.w3schools.com/xquery > > ----------------------------------------------------------- > * Convert each result to its Java representation: > Iterator > <li>Exercise 1</li> > <li>Exercise 2</li> > ----------------------------------------------------------- > > But I am expecting this is - > > Exercise 1 > Exercise 2 > > Actually I want to populate a JComboBox which is a part of my front-end. > So I thought that this piece of code, where it is said "Java > representation", would gimme the output as I required. > > Can you help me a little more..? > Which method will gimme the plain output, without the XML Tags...? So that > I can populate a JComboBox... !! > > > Regards, > Anand Chiney > > > -----Original Message----- > From: Christian Grün [mailto:christian.gruen at gmail.com] > Sent: Saturday, July 07, 2012 5:02 PM > To: Anand Chiney (AIR); BaseX > Subject: Re: Problem with RunQueries.java example!! > > Here's a second feedback (sorry for being distracted): Your query does > return standard Java DOM elements, the toString() method of which > returns "[li: null]". As you are probably interested in the string > representation of the elements, you'll need to replace "toJava()" with > "serialize()": > > System.out.println(item.serialize()); > > Hope this helps, > Christian > ___________________________ > > On Sat, Jul 7, 2012 at 1:26 PM, Christian Grün > <christian.gruen at gmail.com> wrote: >> Your query will yield the expected results if you remove the explicit >> cq.execute(); call. >> >> In the latest snapshot [1], an exception will be returned if the >> result has already been requested. >> >> Hope this helps, >> Christian >> >> [1] http://files.basex.org/releases/latest/ >> ___________________________ >> >>> Dear Christian >>> >>> Please find attached 2 files, MyRunQueries.java and input.xml >>> >>> The .java file is an edited version of RunQueries.java version and the >>> >>> I hope this would be sufficient for you to test. >>> >>> >>> >>> Regards >>> Anand chiney >>> >>> -----Original Message----- >>> From: Christian Grün [mailto:christian.gruen at gmail.com] >>> Sent: Saturday, July 07, 2012 4:34 PM >>> To: Sandeep Yohans >>> Cc: Anand Chiney; basex-talk at mailman.uni-konstanz.de >>> Subject: Re: Problem with RunQueries.java example!! >>> >>> One again I'm sorry Please send us a (small !) example that we can >>> try by ourselves. >>> >>> Thank you in advance, >>> Christian >>> ___________________________ >>> >>> On Sat, Jul 7, 2012 at 1:02 PM, Sandeep Yohans <sandeepy.air at gmail.com> >>> wrote: >>>> Hello Christian, >>>> >>>> We are extracting names from a very long list of names. The > item.toJava() >>>> method call in iterate(query) is returning null. >>>> example output: >>>> >>>> [li: null] >>>> >>>> Rest of the methods are printing output fine. >>>> >>>> >>>> -- >>>> Thanks and Regards >>>> >>>> Sandeep Yohans >>>> Software Developer >>>> Systems - AIR Infotech >>>> Nagpur - India >>>> www.airinfotech.in >>>> Mobile: +91-997-086-5520 >>>> >
CG
Christian Grün9 Jul 2012 14:58 #
Quoted text · Anand Chiney (AIR) · 1 line
> for $x in doc('input.xml')//li return $x/text()
Once again, I'm not sure what you did here, as I always get the DB result…
Quoted text · Anand Chiney (AIR) · 2 lines
> ------------------------Output with DB---------------------- > Example 1Example 2Example 3
However, the following query will explicitly add a newline after each returned item:
  string-join(doc('input.xml')//li, out:nl())
Christian

⚡Generated with XQuery