Overblog Tous les blogs Top blogs Technologie & Science Tous les blogs Technologie & Science
Editer l'article Suivre ce blog Administration + Créer mon blog
MENU

XML2arr

Publié le par damcuvelier


function XML2arr{
    param($xmlfile,$Value)
    
    $erroractionpreference = 'SilentlyContinue'
    $ici = (get-location).path
    if(!$here){$here = $env:TEMP}
    
    set-location $here
    [xml]$xmlcontent = Get-Content -Path $xmlfile
    [string]$header = $xmlcontent.DocumentElement.Name
    $selectedSubheader = $xmlContent.$header.ChildNodes | Where-Object { $_.ChildNodes | Where-Object {$_.'#text' -eq $Value }}
    if(!$selectedSubheader) {$selectedSubheader = $xmlContent.$header.ChildNodes | Where-Object {$_.ChildNodes | Where-Object { $_.'#text' -like "*$Value*" }}}
    
    set-location $ici
return $selectedSubheader
    
}

$ArrXml = XML2arr -xmlfile <xml file fullname> -Value <one value in sub node>

Commenter cet article