Anhang C. XPath-Kurzreferenz
So wie reguläre Ausdrücke die Standardmethode sind, um mit einfachem Text zu arbeiten, ist XPath die Standardmethode, um mit XML zu arbeiten. Deshalb ist XPath etwas, auf das du auf deinen Reisen wahrscheinlich stoßen wirst. Mehrere Cmdlets unterstützen XPath-Abfragen: , , und mehr. Die Tabellen Select-Xml Get-WinEventC-1 und C-2 geben einen schnellen Überblick über die XPath-Konzepte.
Betrachte für diese Beispiele dieses XML-Beispiel:
<AddressBook>
<Person contactType="Personal">
<Name>Lee</Name>
<Phone type="home">555-1212</Phone>
<Phone type="work">555-1213</Phone>
</Person>
<Person contactType="Business">
<Name>Ariel</Name>
<Phone>555-1234</Phone>
</Person>
</AddressBook>
| Syntax | Bedeutung |
|---|---|
|
Stellt die Wurzel des XML-Baums dar. Zum Beispiel: PS > $xml | Select-Xml "/" | Select -Expand Node AddressBook ----------- AddressBook |
|
Navigiert zu dem Knoten namens PS > $xml | Select-Xml "/AddressBook" | Select -Expand Node
Person
------
{Lee, Ariel} |
|
Navigiert zu die noded genannt PS > $xml | Select-Xml "/AddressBook/*/Name" | Select -Expand Node #text ----- Lee Ariel |
|
Findet alle Knoten mit dem Namen PS > $xml | Select-Xml "//Phone" | Select -Expand Node type #text ---- ----- home 555-1212 work 555-1213 555-1234 ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access