Assert-NodeExists

Asserts that a node exist in an XML document.

Syntax

Assert-NodeExists [-Xml] <XmlDocument> [-XPath] <String> [[-DefaultNamespacePrefix] <String>] [[-Message] <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.

Related Commands

Parameters

Name Type Description Required? Pipeline Input Default Value
Xml XmlDocument

The XML document to check.

true false
XPath String

The XPath expression for the node to check.

true false
DefaultNamespacePrefix String

The short prefix for the document's default namespace, if any.

false false
Message String

The message to describe the failure if the assertion fails.

false false

EXAMPLE 1

' '/foo/bar/baz'

Demonstrates how to assert that an XML document contains a node.

EXAMPLE 2

' '/foo/bar/baz' -Message 'XML document not processed!'

Demonstrates how to show a more descriptive error if the assertion fails.