help

Wednesday, 6 July 2011 · 7 messages · last reply 7 Jul 2011
LW
Lusha Wang6 Jul 2011 20:37 #
Hello Everyone I am a newbie to baseX For the following xml, how can I select all the transactions with type udp. This command doesn't work: for $transation in doc('test')//transation where $transation/istype='udp' return <transation>{ $transation/@id }</transation> Thanks a million Serena Wang
<root>
<Journal>
  <Document id="1">
    <Author name="do-not-reply%40domaintools.com" reputation="1.0"/>
    <Time>Sat, 1 May 2010 00:55:20 -0700 (PDT)</Time>
    <Entity>
      <URL>http%3A%2F%2Fwww.domaintools.com%2Fmark-alert%2F</URL>
      <Domain>mexicoisart.com</Domain>
      <IP>199.236.158.250</IP>
    </Entity>
  </Document>
   <Document id="2">
    <Author name="apache%40den.giac.net+%28Apache%29" reputation="10.0"/>
    <Time>Sat, 1 May 2010 10:35:54 +0000 (UTC)</Time>
    <Entity>
      <URL>https%3A%2F%2Fisc.sans.org%2Fdiary.html%3Fstoryid%3D8605</URL>
      <IP>66.28.0.45</IP>
    </Entity>
  </Document>
</Journal>
<transactions>
    <transation id="56977">
      <time>09 Sep 10 23:00:52</time>
      <istype type="type1"/>
      <src>10.8.124.143</src>
      <dst>66.28.0.45</dst>
      <status>INT</status>
    </transation>
</transactions>
<types>
    <type id="type1">
    <name>udp</name>
    </type>
</types>
</root>
CG
Christian Grün6 Jul 2011 20:49 #
Dear Serena, you'll probably need to attach the @type attribute to get the requested result:
  for $transation in doc('test')//transation
  where $transation/istype/@type = 'udp'
  return <transation>{ $transation/@id }</transation>
Christian
Quoted text · Lusha Wang · 55 lines
On Wed, Jul 6, 2011 at 8:37 PM, Lusha Wang <lwang40 at syr.edu> wrote: > Hello Everyone > I am a newbie to baseX > For the following xml, how can I select all the transactions with type > udp. This command doesn't work: > for $transation in doc('test')//transation > where $transation/istype='udp' > return <transation>{ $transation/@id }</transation> > > > Thanks a million > Serena Wang > > <root> > <Journal> > <Document id="1"> > <Author name="do-not-reply%40domaintools.com" reputation="1.0"/> > <Time>Sat, 1 May 2010 00:55:20 -0700 (PDT)</Time> > <Entity> > <URL>http%3A%2F%2Fwww.domaintools.com%2Fmark-alert%2F</URL> > <Domain>mexicoisart.com</Domain> > <IP>199.236.158.250</IP> > </Entity> > </Document> > <Document id="2"> > <Author name="apache%40den.giac.net+%28Apache%29" reputation="10.0"/> > <Time>Sat, 1 May 2010 10:35:54 +0000 (UTC)</Time> > <Entity> > <URL>https%3A%2F%2Fisc.sans.org%2Fdiary.html%3Fstoryid%3D8605</URL> > <IP>66.28.0.45</IP> > </Entity> > </Document> > </Journal> > <transactions> > <transation id="56977"> > <time>09 Sep 10 23:00:52</time> > <istype type="type1"/> > <src>10.8.124.143</src> > <dst>66.28.0.45</dst> > <status>INT</status> > </transation> > </transactions> > <types> > <type id="type1"> > <name>udp</name> > </type> > </types> > </root> > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > >
HV
Huib Verweyin reply to Lusha Wang, 6 Jul 2011, 20:376 Jul 2011 20:51 #
Hi Serena, try changing "transation" to "transaction". Change "$transation/istype='udp'" to "$transaction/istype/@type eq 'type1'". Hartelijke groet, Huib Verweij.
-- Drs. Huib Verweij Senior software developer - The Language Archive Max Planck Institute for Psycholinguistics P.O. Box 310 6500 AH Nijmegen The Netherlands t +31-24-3521911 e huib.verwey at mpi.nl<mailto:huib.verwey at mpi.nl> w http://www.mpi.nl/ Op 6 jul 2011, om 20:37 heeft Lusha Wang het volgende geschreven: Hello Everyone I am a newbie to baseX For the following xml, how can I select all the transactions with type udp. This command doesn't work: for $transation in doc('test')//transation where $transation/istype='udp' return <transation>{ $transation/@id }</transation> Thanks a million Serena Wang <root> <Journal> <Document id="1"> <Author name="do-not-reply%40domaintools.com" reputation="1.0"/> <Time>Sat, 1 May 2010 00:55:20 -0700 (PDT)</Time> <Entity> <URL>http%3A%2F%2Fwww.domaintools.com%2Fmark-alert%2F</URL> <Domain>mexicoisart.com</Domain> <IP>199.236.158.250</IP> </Entity> </Document> <Document id="2"> <Author name="apache%40den.giac.net+%28Apache%29" reputation="10.0"/> <Time>Sat, 1 May 2010 10:35:54 +0000 (UTC)</Time> <Entity> <URL>https%3A%2F%2Fisc.sans.org%2Fdiary.html%3Fstoryid%3D8605</URL> <IP>66.28.0.45</IP> </Entity> </Document> </Journal> <transactions> <transation id="56977"> <time>09 Sep 10 23:00:52</time> <istype type="type1"/> <src>10.8.124.143</src> <dst>66.28.0.45</dst> <status>INT</status> </transation> </transactions> <types> <type id="type1"> <name>udp</name> </type> </types> </root> _______________________________________________ BaseX-Talk mailing list BaseX-Talk at mailman.uni-konstanz.de<mailto:BaseX-Talk at mailman.uni-konstanz.de> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
DP
Dimitar Popovin reply to Lusha Wang, 6 Jul 2011, 20:376 Jul 2011 20:59 #
Hi Here is my suggestion, too :)
let $udpid := $doc//types/type[name = 'udp']/@id/data()
for $transation in $doc//transation
where $transation/istype/@type=$udpid
return <transation>{ $transation/@id }</transation>
Note that BaseX does not treat "id" attributes as node identifiers, so you need to either use "type1" or store the id into a variable (in the above query $udpid). Dimitar
Quoted text · 20:37:02 · 47 lines
Am Mittwoch 06 Juli 2011, 20:37:02 schrieb Lusha Wang: > Hello Everyone > I am a newbie to baseX > For the following xml, how can I select all the transactions with type > udp. This command doesn't work: for $transation in doc('test')//transation > where $transation/istype='udp' > return <transation>{ $transation/@id }</transation> > > > Thanks a million > Serena Wang > > <root> > <Journal> > <Document id="1"> > <Author name="do-not-reply%40domaintools.com" reputation="1.0"/> > <Time>Sat, 1 May 2010 00:55:20 -0700 (PDT)</Time> > <Entity> > <URL>http%3A%2F%2Fwww.domaintools.com%2Fmark-alert%2F</URL> > <Domain>mexicoisart.com</Domain> > <IP>199.236.158.250</IP> > </Entity> > </Document> > <Document id="2"> > <Author name="apache%40den.giac.net+%28Apache%29" reputation="10.0"/> > <Time>Sat, 1 May 2010 10:35:54 +0000 (UTC)</Time> > <Entity> > <URL>https%3A%2F%2Fisc.sans.org%2Fdiary.html%3Fstoryid%3D8605</URL> > <IP>66.28.0.45</IP> > </Entity> > </Document> > </Journal> > <transactions> > <transation id="56977"> > <time>09 Sep 10 23:00:52</time> > <istype type="type1"/> > <src>10.8.124.143</src> > <dst>66.28.0.45</dst> > <status>INT</status> > </transation> > </transactions> > <types> > <type id="type1"> > <name>udp</name> > </type> > </types> > </root>
LW
Lusha Wang7 Jul 2011 02:58 #
HI Guys THanks a lot for your help. It works in the online demo of Basex. However, do you know why nothing is printed out after executing the php code? Can someone point out any documents that I could read so that I wont bother you guys so much. THanks again.
Serena
<?
 echo "Documents whose types are :".$trantype.":<br>";
  $cmd='let $doc:=doc("multi_table") let $udpid := $doc//types/type[name = "'.$trantype.'"]/@id/data() for $transation in $doc//transation where $transation/istype/@type=$udpid return <transation>{ $transation/@id }</transation>';

try {
  // create session
     $session = new Session("localhost", 1984, "admin", "admin");
     $query = $session->query($cmd);
     print $query->init();
     while($query->more()) {
       print  $query->next()."\n";
     }

  // close session
  print $query->close();
  print $session->close();
}
catch (Exception $e) {
  // print exception
  print $e->getMessage();
}
?>

The xml file is
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Journal>
  <Document id="1">
    <Author name="do-not-reply%40domaintools.com" reputation="1.0"/>
    <Time>Sat, 1 May 2010 00:55:20 -0700 (PDT)</Time>
    <Entity>
      <URL>http%3A%2F%2Fwww.domaintools.com%2Fmark-alert%2F</URL>
      <Domain>mexicoisart.com</Domain>
      <IP>199.236.158.250</IP>
    </Entity>
</Journal>
<transactions>
  <ip id="1">
    <value>66.28.0.45</value>
    <transation id="56977">
      <time>09 Sep 10 23:00:52</time>
      <istype type="type1"/>
      <src>10.8.124.143</src>
      <dst>66.28.0.45</dst>
      <status>INT</status>
    </transation>
  </ip>
  <ip id="2">
    <value>66.28.0.61</value>
    <transation id="63050">
      <time>09 Sep 10 23:01:00</time>
      <istype type="type1"/>
      <src>10.8.124.143</src>
      <dst>66.28.0.61</dst>
      <status>INT</status>
    </transation>
  </ip>
</transactions>
<types>
    <type id="type1">
    <name>udp</name>
    </type>
</types>
</root>
AW
Andreas Weiler7 Jul 2011 08:22 #
Hi Lusha, the result is printed but not shown in the browser (because of the tags "transation" around your result). This one works: <?php /* * This example shows how database commands can be executed. * Documentation: http://basex.org/api * * (C) BaseX Team 2005-11, ISC License */ include("BaseXClient.php"); $trantype = "udp"; echo "Documents whose types are :".$trantype.":<br>"; $cmd='let $doc:=doc("multi_table") let $udpid := $doc//types/type[name = "'.$trantype.'"]/@id/data() for $transation in $doc//transation where $transation/istype/@type=$udpid return$transation/@id';
try {
 // create session
    $session = new Session("localhost", 1984, "admin", "admin");
    $query = $session->query($cmd);
    print $query->init();
    while($query->more()) {
      print  $query->next()."\n";
    }

 // close session
 print $query->close();
 print $session->close();
}
catch (Exception $e) {
 // print exception
 print $e->getMessage();
}
?>
The only existing documents are the official BaseX documentation: docs.basex.org -- Andreas
Quoted text · Lusha Wang · 76 lines
On 07.07.2011, at 02:58, Lusha Wang wrote: > HI Guys > THanks a lot for your help. It works in the online demo of Basex. However, do you know why nothing is printed out after executing the php code? Can someone point out any documents that I could read so that I wont bother you guys so much. THanks again. > > > Serena > <? > echo "Documents whose types are :".$trantype.":<br>"; > $cmd='let $doc:=doc("multi_table") let $udpid := $doc//types/type[name = "'.$trantype.'"]/@id/data() for $transation in $doc//transation where $transation/istype/@type=$udpid return <transation>{ $transation/@id }</transation>'; > > try { > // create session > $session = new Session("localhost", 1984, "admin", "admin"); > $query = $session->query($cmd); > print $query->init(); > while($query->more()) { > print $query->next()."\n"; > } > > // close session > print $query->close(); > print $session->close(); > } > catch (Exception $e) { > // print exception > print $e->getMessage(); > } > ?> > > The xml file is > <?xml version="1.0" encoding="UTF-8"?> > <root> > <Journal> > <Document id="1"> > <Author name="do-not-reply%40domaintools.com" reputation="1.0"/> > <Time>Sat, 1 May 2010 00:55:20 -0700 (PDT)</Time> > <Entity> > <URL>http%3A%2F%2Fwww.domaintools.com%2Fmark-alert%2F</URL> > <Domain>mexicoisart.com</Domain> > <IP>199.236.158.250</IP> > </Entity> > </Journal> > <transactions> > <ip id="1"> > <value>66.28.0.45</value> > <transation id="56977"> > <time>09 Sep 10 23:00:52</time> > <istype type="type1"/> > <src>10.8.124.143</src> > <dst>66.28.0.45</dst> > <status>INT</status> > </transation> > </ip> > <ip id="2"> > <value>66.28.0.61</value> > <transation id="63050"> > <time>09 Sep 10 23:01:00</time> > <istype type="type1"/> > <src>10.8.124.143</src> > <dst>66.28.0.61</dst> > <status>INT</status> > </transation> > </ip> > </transactions> > <types> > <type id="type1"> > <name>udp</name> > </type> > </types> > </root> > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
MS
Michael Seiferlein reply to Lusha Wang, 7 Jul 2011, 02:587 Jul 2011 10:47 #
Hi Serena, can you check if the following query works for you? https://gist.github.com/c9b372ada66580ff8e79 It wraps the results in <pre> Tags, and should display in any browser. Please also note the nowdoc syntax, it allows you to format your queries a little more readable :) [1] Hope this helps. Kind regards Michael [1] http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc
Quoted text · Lusha Wang · 3 lines
Am 07.07.2011 um 02:58 schrieb Lusha Wang: > HI Guys > THanks a lot for your help. It works in the online demo of Basex. However, do you know why nothing is printed out after executing the php code? Can someone point out any documents that I could read so that I wont bother you guys so much. THanks again.

⚡Generated with XQuery