2015-05-15 62 views
1

所以我有这样的XML数据库XPATH帮助选择元件

<uni> 
<!-- SUBJECTS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> 
    <subjects> 
    <subject code="XYZ111"> 
     <title>Java for housewives</title> 
     <credits>6</credits> 
     <laboratories> 
      <laboratory num="lab1"> 
      <date>12-MAR-2009</date> 
      <topics> 
       <topic>variables</topic> 
       <topic>constants</topic> 
      </topics> 
      <description>Declarations of variables and constants</description> 
     </laboratory> 
      <laboratory num="lab2"> 
      <date>12-APR-2009</date> 
      <topics> 
       <topic>expressions</topic> 
      </topics> 
      <description>Types of expressions</description> 
     </laboratory> 
      <laboratory num="lab3"> 
      <date>12-MAY-2009</date> 
      <topics> 
       <topic>conditionals</topic> 
       <topic>loops</topic> 
      </topics> 
      <description>Control statements</description> 
     </laboratory> 
     </laboratories> 
    </subject> 
    <subject code="XYZ235"> 
     <title>Database systems for politicians</title> 
     <credits>6</credits> 
     <laboratories> 
     <laboratory num="lab1"> 
      <date>10-JAN-2001</date> 
      <topics> 
       <topic>classes</topic> 
       <topic>associations</topic> 
       <topic>properties</topic> 
       </topics> 
       <description>Conceptual modeling</description> 
     </laboratory> 
     <laboratory num="lab2"> 
      <date>10-JAN-2002</date> 
      <topics> 
       <topic>relational tables</topic> 
       <topic>primary keys</topic> 
       <topic>foreign keys</topic> 
       </topics> 
       <description>Relational data model</description> 
     </laboratory> 
     </laboratories> 
    </subject> 
    <subject code="XYZ987"> 
     <title>Ethics for car dealers</title> 
     <credits>6</credits> 
    </subject> 
    <subject code="XYZ101"> 
     <title>Programming for mathematicians</title> 
     <credits>6000</credits> 
     <laboratories> 
     <laboratory num="lab1"> 
      <date>10-JAN-2002</date> 
      <topics> 
       <topic>abstract algebra</topic> 
       </topics> 
      <description>Hilbert spaces of programming languages</description> 
     </laboratory> 
     <laboratory num="lab2"> 
      <date>13-MAY-2002</date> 
      <topics> 
       <topic>topology</topic> 
       </topics> 
      <description>Theory of homothopy</description> 
     </laboratory> 
     </laboratories> 
    </subject> 
     <subject code="ZZZ777"> 
     <title>Cooking</title> 
     <credits>5</credits> 
     <laboratories/> 
     </subject> 
    <subject code="ZZZ778"> 
     <title>Dancing</title> 
     <credits>5</credits> 
     <laboratories/> 
     </subject> 
     <subject code="ABC123"> 
     <title>General theory of everything</title> 
     <credits>4</credits> 
     <laboratories> 
     <laboratory num="lab1"> 
      <date>20-JAN-2012</date> 
      <topics> 
       <topic>space</topic> 
       </topics> 
      <description>Nothing really interesting</description> 
     </laboratory> 
      </laboratories> 
     </subject> 
    </subjects> 
<!-- ENROLMENTS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> 
     <enrolments> 
     <enrolment snum="d2345" code="ABC123"> 
     <date>12-DEC-2011</date> 
     <status>dropped</status> 
     <time>20</time> 
     <IP>16.23.234.002</IP> 
     <lab-enrolments> 
      <laboratory num="lab1"/> 
     </lab-enrolments> 
     </enrolment> 
     <enrolment snum="d2346" code="ABC123"> 
     <date>12-DEC-2011</date> 
     <status>dropped</status> 
     <time>2</time> 
     <IP>16.23.234.003</IP> 
     <lab-enrolments> 
      <laboratory num="lab1"/> 
     </lab-enrolments> 
     </enrolment> 
     <enrolment snum="d2347" code="ABC123"> 
     <date>12-DEC-2011</date> 
     <status>dropped</status> 
     <time>10</time> 
     <IP>16.23.234.003</IP> 
     </enrolment> 
     <enrolment snum="d2348" code="ABC123"> 
     <date>12-DEC-2011</date> 
     <status>dropped</status> 
     <time>20</time> 
     <IP>16.23.234.025</IP> 
     </enrolment> 
     <enrolment snum="d6767" code="ABC123"> 
     <date>13-DEC-2011</date> 
     <status>valid</status> 
     <time>5</time> 
     <IP>16.23.234.202</IP> 
     </enrolment> 
     <enrolment snum="d2345" code="ZZZ778"> 
     <date>14-DEC-2007</date> 
     <status>valid</status> 
     <time>10</time> 
     <IP>16.23.234.402</IP> 
     </enrolment> 
     <enrolment snum="d6767" code="ZZZ777"> 
     <date>12-SEP-2005</date> 
     <status>valid</status> 
     <time>15</time> 
     <IP>16.23.234.202</IP> 
     </enrolment> 
     <enrolment snum="d2330" code="XYZ101"> 
     <date>01-JAN-2002</date> 
     <status>valid</status> 
     <time>3</time> 
     <IP>16.23.234.203</IP> 
     <lab-enrolments> 
      <laboratory num="lab1"/> 
      <laboratory num="lab2"/> 
     </lab-enrolments> 

     </enrolment> 
     <enrolment snum="d2349" code="XYZ101"> 
     <date>01-JAN-2002</date> 
     <status>valid</status> 
     <time>7</time> 
     <IP>16.23.234.202</IP> 
     <lab-enrolments> 
      <laboratory num="lab1"/> 
      <laboratory num="lab2"/> 
     </lab-enrolments> 
     </enrolment> 
     <enrolment snum="d2341" code="XYZ101"> 
     <date>01-JAN-2002</date> 
     <status>valid</status> 
     <time>6</time> 
     <IP>16.23.234.201</IP> 
     <lab-enrolments> 
      <laboratory num="lab1"/> 
     </lab-enrolments> 
     </enrolment> 
     <enrolment snum="d6767" code="XYZ101"> 
     <date>01-JAN-2002</date> 
     <status>provisional</status> 
     <time>5</time> 
     <IP>16.23.234.002</IP> 
     </enrolment> 
     <enrolment snum="d6767" code="XYZ235"> 
     <date>31-DEC-2000</date> 
     <status>provisional</status> 
     <time>30</time> 
     <IP>16.23.234.602</IP> 
     </enrolment> 
     </enrolments> 
</uni> 

而且我试图找到的科目,包括对抽象代数实验室的标题。到目前为止,这是最好的答案我可以想出,但它没有找到一个匹配:/ //uni/subjects/subject/laboratories/laboratory/topics/topic[text()="abstract algebra"]

回答

2

你可以试试这个方法:

//subject[laboratories/laboratory/topics/topic="abstract algebra"]/title 
3

您正在寻找这样的:

//subject[laboratories/laboratory/topics/topic[.="abstract algebra"]]/title 
+0

这就是我正在寻找的^ _ ^,我曾尝试过类似的东西,只是不知道可以在对方使用方括号。谢谢堆:) – Impulse