Let me provide a little more detail. My real XML document is very long but I'll provide a small part of it here.
<?xml version="1.0" encoding="utf-16"?>
<ShowPlanXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="1.1" Build="10.50.2500.0" xmlns="http://schemas.microsoft.com/sqlserver/2004/07/showplan">
<BatchSequence>
<Batch>
<Statements>
<StmtSimple StatementCompId="2" StatementEstRows="25.6162" StatementId="1" StatementOptmLevel="FULL" StatementSubTreeCost="16728.7" StatementText="Select *
From #SalePurchaseData 
Inner
Join v_BP_Integ_Tax_TrnHdr (NoLock) On #SalePurchaseData.XHdrID = v_BP_Integ_Tax_TrnHdr.XHdrID 
Inner Join v_BP_Integ_Tax_AcctDet (NoLock) On #SalePurchaseData.AcctDtlID = v_BP_Integ_Tax_AcctDet.AcctDtlID
Inner Join AccountDetail
(NoLock) On #SalePurchaseData.AcctDtlID = AccountDetail.AcctDtlID 
inner Join AccountingPeriod reportingperiod (NoLock) on reportingperiod.AccntngPrdID = @i_AccntngPrdID
Inner join accountingperiod (NoLock) On accountingperiod.AccntngPrdID
= accountdetail.AcctDtlAccntngPrdID
Inner Join TransactionHeader (NoLock) on #SalePurchaseData.XHdrID = Transactionheader.XHdrID
Inner Join v_UOMConversion NetGrossUOM (NoLock) On NetGrossUOM.FromUOM = 
 (select
BaseVolumeUnitOfMeasureId from ConfigSystem where id = 1)
And NetGrossUOM.ToUOM = v_BP_Integ_Tax_TrnHdr.ToUOMID
Inner Join v_UOMConversion InvUOM (NoLock) On InvUOM.FromUOM = NetGrossUOM.FromUOM
and InvUOM.ToUOM
= Coalesce(v_BP_Integ_Tax_AcctDet.InvoiceUomID,AccountDetail.AcctDtlUOMID)
" StatementType="SELECT" QueryHash="0xB54D2EF0A2868982" QueryPlanHash="0x10861F788BCF956E">
<StatementSetOptions ANSI_NULLS="true" ANSI_PADDING="true" ANSI_WARNINGS="true" ARITHABORT="true" CONCAT_NULL_YIELDS_NULL="true" NUMERIC_ROUNDABORT="false" QUOTED_IDENTIFIER="true" />
<QueryPlan DegreeOfParallelism="4" MemoryGrant="3269664" CachedPlanSize="5616" CompileTime="4675" CompileCPU="4629" CompileMemory="65968">
<RelOp AvgRowSize="33719" EstimateCPU="2.56162E-06" EstimateIO="0" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="25.6162" LogicalOp="Compute Scalar" NodeId="0" Parallel="false" PhysicalOp="Compute
Scalar" EstimatedTotalSubtreeCost="16728.7">
</RelOp>
<ParameterList>
<ColumnReference Column="@i_AccntngPrdID" ParameterRuntimeValue="(278)" />
</ParameterList>
</QueryPlan>
</StmtSimple>
</Statements>
</Batch>
</BatchSequence>
</ShowPlanXML>
I've been able to manually test getting pieces of data I want as follows. Similar to the Scripting Guy Articles that Yan refrenced below.
$XML_Object | Get-Member -MemberType Properties
$XML_Object.ShowPlanXML | Get-Member -MemberType Properties
$XML_Object.ShowPlanXML.BatchSequence | Get-Member -MemberType Properties
$XML_Object.ShowPlanXML.BatchSequence.Batch | Get-Member -MemberType Properties
$XML_Object.ShowPlanXML.BatchSequence.Batch.Statements | Get-Member -MemberType Properties
$XML_Object.ShowPlanXML.BatchSequence.Batch.Statements.StmtSimple | Get-Member -MemberType Properties
$XML_Object.ShowPlanXML.BatchSequence.Batch.Statements.StmtSimple.QueryPlan | Get-Member -MemberType Properties
$Current_Node = $XML_Object.ShowPlanXML.BatchSequence.Batch.Statements.StmtSimple.QueryPlan.RelOp
$Grand_ETSC = $Current_Node.EstimatedTotalSubtreeCost | Where { [int]$Current_Node.NodeId -Eq 0}
$Grand_ETSC
While you can see how I can manually go through successive levels of this xml document and get some data I want out of it I'm trying to figure out now just how to recursively go through the whole thing.
I try the following function and function call but it only goes 2 levels deep and then errors.
Function Recurse-Levels
{
Param
(
[Parameter(Position=0,Mandatory=1)]
[object]$Some_Object
)
$Current_Level = $Some_Object
$Properties = $Current_Level | Get-Member -MemberType Properties
If ($Properties)
{
ForEach ($Property In $Properties)
{
$Child_Property = $Property.Name
Write-Verbose $Child_Property
$Child_Node = $XML_Object.$Child_Property
Write-Verbose $Child_Node
Recurse-Levels $Child_Node
}
}
}
Recurse-Levels $XML_Object
I see output like the following
VERBOSE: ShowPlanXML
VERBOSE: System.Xml.XmlElement
VERBOSE: BatchSequence
out-lineoutput : The OS handle's position is not what FileStream expected. Do not use a handle simultaneously in one Fi
leStream and in Win32 code or another FileStream. This may cause data loss.
+ CategoryInfo : NotSpecified: (:) [out-lineoutput], IOException
+ FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.OutLineOutputCommand
Perhaps I need to wrap my call in a Try/Catch so that if it tries to operate on something with no properties it doesn't error out. Anyway, I think I am close but just missing something obvious.
Thanks to all who have looked at this and thought about it.