Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First step is to load your xml string into an XmlDocument, using powershell's unique ability to cast strings to [xml]</p> <pre class="lang-sh prettyprint-override"><code>$doc = [xml]@' &lt;xml&gt; &lt;Section name="BackendStatus"&gt; &lt;BEName BE="crust" Status="1" /&gt; &lt;BEName BE="pizza" Status="1" /&gt; &lt;BEName BE="pie" Status="1" /&gt; &lt;BEName BE="bread" Status="1" /&gt; &lt;BEName BE="Kulcha" Status="1" /&gt; &lt;BEName BE="kulfi" Status="1" /&gt; &lt;BEName BE="cheese" Status="1" /&gt; &lt;/Section&gt; &lt;/xml&gt; '@ </code></pre> <p>Powershell makes it really easy to parse xml with the dot notation. This statement will produce a sequence of XmlElements for your BEName elements:</p> <pre class="lang-sh prettyprint-override"><code>$doc.xml.Section.BEName </code></pre> <p>Then you can pipe these objects into the where-object cmdlet to filter down the results. You can use ? as a shortcut for where</p> <pre class="lang-sh prettyprint-override"><code>$doc.xml.Section.BEName | ? { $_.Status -eq 1 } </code></pre> <p>The expression inside the braces will be evaluated for each XmlElement in the pipeline, and only those that have a Status of 1 will be returned. The $_ operator refers to the current object in the pipeline (an XmlElement).</p> <p>If you need to do something for every object in your pipeline, you can pipe the objects into the foreach-object cmdlet, which executes a block for every object in the pipeline. % is a shortcut for foreach:</p> <pre class="lang-sh prettyprint-override"><code>$doc.xml.Section.BEName | ? { $_.Status -eq 1 } | % { $_.BE + " is delicious" } </code></pre> <p>Powershell is great at this stuff. It's really easy to assemble pipelines of objects, filter pipelines, and do operations on each object in the pipeline.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload