< Back

Assert-NodeExists

Sun Jan 12, 2020 5:47 pm

NAME Assert-NodeExists



SYNOPSIS

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.





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 expression for the node to check.



Required? true

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



-DefaultNamespacePrefix <String>

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



Required? false

Position? 3

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Message <String>

The message to describe the failure if the assertion fails.



Required? false

Position? 4

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 --------------------------



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



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









-------------------------- EXAMPLE 2 --------------------------



Assert-NodeExists '<foo><bar><baz /></bar></foo>' '/foo/bar/baz' -Message 'XML document not processed!'



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











RELATED LINKS

Assert-NodeDoesNotExist

Test-NodeExists