Home > Software engineering >  Is it possible to retrieve attribute names matching certain condition using xpath1.0?
Is it possible to retrieve attribute names matching certain condition using xpath1.0?

Time:09-21

<Tasks>
 <Task>
  <UID>14</UID>
  <Name>Entertainment</Name>
  <ID>2</ID>
  <PerComp>22</PerComp>
 </Task>
 <Task>
  <UID>12</UID>
  <Name>Movie</Name>
  <ID>1</ID>
  <PerComp>55</PerComp>
 </Task>
 <Task>
  <UID>15</UID>
  <Name>Star</Name>
  <ID>3</ID>
  <PerComp>100</PerComp>
 </Task>
</Tasks>
    

Is it possible to list all task names in comma separator from the above XML with condition PerComp not equal to 100? There may be 100's of tasks and I want all task names?

Expected result:

Entertainment, Movie, etc.

CodePudding user response:

XPath 1.0 allows you to retrieve the set of nodes (which are elements, not attributes - your XML contains no attributes), but it does not allow you to combine their values into a string; that would have to be done by the calling application.

//Task[not(PerComp = 100)]/Name
  • Related