< Back

Test-NodeExists

Sun Jan 12, 2020 5:55 pm

NAME Test-NodeExists



SYNOPSIS

Tests if a node exists in an XML document.





SYNTAX

Test-NodeExists [-Xml] <XmlDocument> [-XPath] <String> [[-DefaultNamespacePrefix] <String>] [<CommonParameters>]





DESCRIPTION

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.





PARAMETERS

-Xml <XmlDocument>

The XML Document to check



Required? true

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-XPath <String>

The XPath to use for the node whose existence to check.



Required? true

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



-DefaultNamespacePrefix <String>

The prefix of the XML document's default namespace.



Required? false

Position? 3

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



Test-NodeExists '<foo><bar><baz /></bar></foo>' '/foo/bar/baz'



Returns `$true` if a node selected by `XPath` is found.











RELATED LINKS

Assert-NodeExists

Assert-NodeDoesNotExist