XML : Select on xml using xpath in powershell

Im working with powershell to select some attributes on powershell, but it doesn't seem to work.

My current code is like that:

  [xml]$xml = Get-Content 'C:\Makro-Test\quandata.xml'  $xml.QUANDATASET.GROUPDATA.GROUP.SAMPLELISTDATA.SAMPLE| foreach { $_.id + ":" + $_.name + ":" + $_.COMPOUND.id + ":" + $_.COMPOUND.name + ":" + $_.COMPOUND.PEAK.analconc}    

the xml file looks like that:

  <?xml version="1.0"?>  <QUANDATASET>    <XMLFILE>    <DATASET>    <GROUPDATA>      <GROUP>        <METHODDATA/>        <SAMPLELISTDATA>          <SAMPLE id="1" groupid="1" name="Routine_2016_05_30_002">            <COMPOUND id="1" sampleid="1" groupid="1" name="Leu">              <PEAK foundscan="0" analconc="0.023423456">                <ISPEAK/>              </PEAK>            </COMPOUND>            <COMPOUND id="2" sampleid="1" groupid="1" name="Iso">               <PEAK foundscan="0" analconc="0.123456789">                 <ISPEAK/>               </PEAK>            </COMPOUND>            <COMPOUND id="3" sampleid="1" groupid="1" name="Thre">            ...            ...            ...          <SAMPLE id="2" groupid="1" name="Routine_2016_05_30_003">            <COMPOUND id="1" sampleid="2" groupid="1" name="Leu">            ....            ....            ....    

And the output like that:

  1:Aminoacids_Routine_2016_05_30_002:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23:Leu Iso Thre Val Lys Met Phen Try His Gly Ala Ser Arg Cys Tyr Pro Glu Glut Asp Aspa Tau Orn Cit:0.0000000000     0.0000000000   0.0000000000  0.0000000000 0.0000000000  0.0000000000  0.0000000000  2:Aminoacids_Routine_2016_05_30_003:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23:Leu Iso Thre Val Lys Met Phen Try His Gly Ala Ser Arg Cys Tyr Pro Glu Glut Asp Aspa Tau Orn Cit:0.0000000000 0.2336617286 0.2147717292 0.2252815136  0.2299108827 0.2395318825  0.0000000000    0.0000000000 0.0000000000  0.2074479299     0.0000000000  0.0000000000    

.... .... `

But i want the output looks like that:

  1;Aminoacids_Routine_2016_05_30_002;1;Leu;0.0000000000  2;Aminoacids_Routine_2016_05_30_002;2;Iso;0.0000000000  ...  1;Aminoacids_Routine_2016_05_30_003;1;Leu;0.0000000000  2;Aminoacids_Routine_2016_05_30_003;2;Iso;0.2336617286  ....    

Any ideas? Thanks in advance!!

No comments:

Post a Comment