Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

XML SelectNode - Parenting

$
0
0

Taking this XML file

<?xml version="1.0" encoding="UTF-8"?>
<Os>
  <O>
    <name>OName1</name>
    <id>1</id>
    <tags>
    </tags>
    <Qs>
      <Q>
        <name>QName1</name>
        <id>1</id>
        <tags>
        </tags>
        <Rs>
          <R>
            <name>RName1</name>
            <id>100</id>
            <tags>
              <name>RefID</name>
              <value>72</value>
            </tags>
          </R>
          <R>
            <name>RName2</name>
            <id>121</id>
            <tags>
            </tags>
          </R>
          <R>
            <name>RName3</name>
            <id>126</id>
            <tags>
            </tags>
          </R>
		 </Rs>
		</Q>
   </Qs>
 </O>
   <O>
    <name>OName2</name>
	<id>2</id>
	</O>
</Os>	

And this PS code:

[xml]$xml1 = get-content D:\Powershell\Chunk.xml
$xml1.SelectSingleNode("//O//Q//R[id=126]")

The selectsinglenode returns

name                                                        id                                                          tags
----                                                        --                                                          ----
RName3                                                      126

I'm happy with this, what I would like now is to get the parenting nodes tree based on name or ID, such as:

Oname1 \ Qname1 \ RName3 -> based on the Name tag

or

1 \ 1 \ 126 -> based on the ID tag

Please HELP, I'm completly stuck and new with XML

TIA


Life is short, Enjoy it now. Cyreli



Viewing all articles
Browse latest Browse all 2562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>