XML : Nodelist with values and parent's attribute as names

I'm new to XML files and am trying to get out some values using xpath. I will plot this values in Jenkins using the Plot plugin. This takes the element names on the x-axis and the element value on the y-axis.

My xml file looks like:

  <?xml version="1.0" encoding="UTF-8" ?>  <foo>      <file file_name="file1.c">          <metrics>              <metric id="M1">15</metric>              <metric id="M2">7</metric>              <metric id="M3">9</metric>          </metrics>      </file>      <file file_name="file2.c">          <metrics>              <metric id="M1">1110</metric>              <metric id="M2">56</metric>              <metric id="M3">1</metric>          </metrics>      </file>  </foo>    

I want to plot M1 for all file_name, therefore what I need to get back using xpath is a nodelist like

  <file1.c>15</file1.c>  <file2.c>1110</file1.c>    

I tried

  //file/metrics/*[@id='M1']    

but so I get

  <metric id="M1">15</metric>  <metric id="M1">15</metric>    

I found some similar questions, but couldn't adapt it to my case: This for example gets back the parent element including all childs.

How can I achieve what I need? Thank you for any advice!

No comments:

Post a Comment