0

Hello all and thank's for your help

in a very long XML document i need to read content for following lines in powershell

1)

<wd:Address_Data wd:Effective_Date="2015-06-01-07:00" wd:Address_Format_Type="Extended" wd:Formatted_Address="my_adress_XXX&#xa;ZZZ&#xa;WWW" wd:Defaulted_Business_Site_Address="0">

2)

<wd:Address_Line_Data wd:Type="ADDRESS_LINE_1" wd:Descriptor="Street Name and Type">my_adressXXX</wd:Address_Line_Data>

i've tried many (without success) such as

$o.Adr = $my_XML.SelectNodes('./wd:hierarchy1/wd:hierarchy2/wd:hierarchy3/wd:Address_Data/wd:ID@wd:Formatted_Address]]', $NM).InnerText

or

$o.Adrl1 = $workerJobData.SelectNodes('./wd:hierarchy1/wd:hierarchy2/wd:hierarchy3/wd:Address_Data/wd:ID[@wd:type="ADDRESS_LINE_1" and .Descriptor="Street Name and Type"]]', $NM).InnerText

where NM is the top-level xml node

            foreach ($x in $elements.SelectNodes('//wd:WWW', $NM)) 

regarding 1) i will need to read content whatever Effective_Date is (use the latest if many)

i'm sure of my path as i already read other "single" entries but i have difficulties adressing "multi-properties inside xml key" such as in my samples

Regards

Emmanuel

  • 1
    You need to reveal the header of your xml file as you apperarently using a namespace. I suspect that you will find you general answer here: [https://stackoverflow.com/a/18881581/1701026] – iRon Mar 01 '20 at 08:09
  • hi this link is not very helpful: i can browse the xml node just higher than mineby using – Emmanuel Manent Mar 01 '20 at 15:09
  • hi this link is not very helpful: i can browse the xml node just higher than mine by using `$o.Municipality= $workerJobData.SelectNodes('./wd:Position_Data/wd:Business_Site_Summary_Data/wd:Address_Data/wd:Municipality', $NM).InnerText` ---- the xml node is `London` for this one ...... i really think my problem is to query the attribute . – Emmanuel Manent Mar 01 '20 at 15:15
  • i think the answer should be close to `$o.Adr=$workerJobData.SelectNodes('./wd:Position_Data/wd:Business_Site_Summary_Data/wd:Address_Data/wd:Address_Line_Data', $NM) | Select Formatted_Address` but i get the following answer: @{Formatted_Address=} (and not the content of the atribute i'm looking for – Emmanuel Manent Mar 01 '20 at 15:19
  • i've found for 1) !! `$workerJobData.Position_Data.Business_Site_Summary_Data.Address_Data.Formatted_Address ` gives me the correct answer (without checking multiple data to order by wd:Effective_Date.... on the other side `$workerJobData.Position_Data.Business_Site_Summary_Data.Address_Data.Address_Line_Data.Innertext` gives me a correct answer but only for the 1st type ADDRESS_LINE_x found and it is staying on it, i need to fiilter by type – Emmanuel Manent Mar 01 '20 at 21:04

1 Answers1

0

ok i finally found out! , for those interested

for 1) $adr=$workerJobData.Position_Data.Business_Site_Summary_Data.Address_Data.Formatted_Address

and for 2) $temp=$workerJobData.Position_Data.Business_Site_Summary_Data.Address_Data.Address_Line_Data | Where-Object {$_.type -eq 'ADDRESS_LINE_1'}
$Adrl1=$temp.Innertext