Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

XPath

For searching in XML documents with the help of XPath (XPath is a W3C standard; see [W3C01]) the class XmlDocument supports the methods SelectNodes() and SelectSingleNode(). In PSCX, there is the commandlet Select-Xml (see Table 12.1).

Table 12.1. Examples for the Use of XPath
$doc.SelectNodes("//URL")

Displays all <URL> elements
or 
select-Xml h:\demo\powershell\xml\
websites.xml -XPath "//URL" |
select innerxml

$doc.SelectNodes("//Website/@ID")

 
or
select-Xml h:\demo\powershell\
xml\websites.xml -XPath
"//Website/@ID" | select innerxml

$doc.SelectSingleNode
("//Website[@ID=3]/URL")

Displays all ID attributes of all <Website> elements
or 
select-Xml h:\demo\powershell\
xml\websites.xml -XPath
"//Website[@ID=3]/URL" |
select innerxml

Displays the <URL>-element of the <Website> elements with the attribute value 3 in the attribute ID



  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint