0

I want to verify that an xml file has data past any first tier node.

My .xml file looks like:

<?xml version="1.0" encoding="utf-8"?>
<[NodeName] xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <[NodeNameHere] "information here" />
</Node1>

The [NodeNameHere] and [NodeName] changes between files so I can't use that to test to see if there are child nodes.

So far I've tried using:

$xmlFile.LastChild.HasChildNodes
$xmlFile.FirstChild.HasChildNodes

In the above example the LastChild returns true while the FirstChild returns false. This would work, however there may be another node (not first or last) that contains data.

Speerian
  • 1,138
  • 1
  • 12
  • 29

1 Answers1

1

Have you tried:

$xmlFile.DocumentElement.HasChildNodes
campbell.rw
  • 1,366
  • 12
  • 22
  • That seems to do the trick. Better than `$xmlFile.ChildNodes.HasChildNodes`, then checking the response for `$true`. – Speerian Aug 06 '15 at 19:05