All Things WinBatch > WinBatch

Read data from an XML file.

<< < (2/2)

stanl:
Looks like I missed a step. Attached is output from updated snippet. The XML is more like Json and could be serialized easier if it was. Will try to move the logic into either  WB CLR or MSXML, time permitting.

--- Code: ---
#parse xml into bar-delimited text for properties
#change xml file/path and txt output as needed
$file = "c:\temp\zombies.txt"
if (Test-Path $file ) {Remove-Item $file}
$data = "class|property|value" | out-file $file
[xml]$info = Get-Content -Path C:\temp\zombies.xml
$base = $info.FirstChild
if ($base.HasChildNodes -eq $true )
{
   ForEach ($class in $base.ChildNodes)
   {
       $name = $class.name
       $props = $class.property
       $grps = $class.effect_group
       ForEach ($prop in $props)
       {
          $data = $name + "|" +$prop.name + "|" + $prop.value
          $data | Out-File $file -Append
       }
       if ($grps.HasChildNodes -eq $true)
       {
          ForEach ($grp in $grps.ChildNodes)
          {
             $data = $name + "|" +$grp.name + "|" + $grp.value
             $data | Out-File $file -Append
          }
       }


   }
}
Exit



--- End code ---

Navigation

[0] Message Index

[*] Previous page

Go to full version