Tests if a node exists in an XML document.
Test-NodeExists [-Xml] <XmlDocument> [-XPath] <String> [[-DefaultNamespacePrefix] <String>] [<CommonParameters>]
It's usually pretty easy in PowerShell to check if a node exists in an XML document: simply test if a property exists on that node. If, however, that XML document has namespaces, you have to do extra setup with the XML document so that you can find the node. This function does that work for you.
Name | Type | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
Xml | XmlDocument | The XML Document to check |
true | false | |
XPath | String | The XPath to use for the node whose existence to check. |
true | false | |
DefaultNamespacePrefix | String | The prefix of the XML document's default namespace. |
false | false |
' '/foo/bar/baz'
Returns $true
if a node selected by XPath
is found.