Skip to content

Instantly share code, notes, and snippets.

@ninmonkey
Last active July 15, 2020 16:05
Show Gist options
  • Select an option

  • Save ninmonkey/598473a71ddcd2cc2647ecb690aafd4a to your computer and use it in GitHub Desktop.

Select an option

Save ninmonkey/598473a71ddcd2cc2647ecb690aafd4a to your computer and use it in GitHub Desktop.
test for mapping xml to json
{
"divingmask": {
"PreferredContainer": [
"System.Collections.Hashtable",
"System.Collections.Hashtable"
],
"Attrs": {
"category": "Equipment",
"impactsoundtag": "impact_metal_light",
"identifier": "divingmask",
"cargocontaineridentifier": "metalcrate",
"Tags": "smallitem,diving,divingmask",
"name": "",
"description": "",
"scale": "0.5"
}
},
"divingsuit": {
"PreferredContainer": {
"spawnprobability": "0.8",
"primary": "divingsuitcontainer"
},
"Attrs": {
"category": "Equipment",
"impactsoundtag": "impact_metal_heavy",
"fireproof": "true",
"identifier": "divingsuit",
"description": "",
"tags": "diving,divingsuit,light",
"name": "",
"scale": "0.5"
}
},
"underwaterscooter": {
"PreferredContainer": {
"primary": "divingcab",
"maxamount": "3",
"minamount": "1",
"spawnprobability": "1"
},
"Attrs": {
"category": "Equipment",
"impactsoundtag": "impact_metal_light",
"identifier": "underwaterscooter",
"cargocontaineridentifier": "metalcrate",
"isshootable": "true",
"Tags": "smallitem,provocative,light",
"name": "",
"description": "",
"Scale": "0.32"
}
},
"oxygenitetank": {
"PreferredContainer": [
"System.Collections.Hashtable",
"System.Collections.Hashtable"
],
"Attrs": {
"category": "Equipment,Misc",
"impactsoundtag": "impact_metal_light",
"description": "",
"identifier": "oxygenitetank",
"Tags": "smallitem,oxygensource",
"name": "",
"scale": "0.3"
}
},
"oxygentank": {
"PreferredContainer": [
"System.Collections.Hashtable",
"System.Collections.Hashtable",
"System.Collections.Hashtable",
"System.Collections.Hashtable"
],
"Attrs": {
"category": "Equipment,Misc",
"impactsoundtag": "impact_metal_light",
"identifier": "oxygentank",
"cargocontaineridentifier": "metalcrate",
"Tags": "oxygentank,smallitem,oxygensource",
"name": "",
"scale": "0.3"
}
}
}
{
"divingmask": {
"Attrs": {
"category": "Equipment",
"impactsoundtag": "impact_metal_light",
"identifier": "divingmask",
"cargocontaineridentifier": "metalcrate",
"Tags": "smallitem,diving,divingmask",
"name": "",
"description": "",
"scale": "0.5"
}
},
"divingsuit": {
"Attrs": {
"category": "Equipment",
"impactsoundtag": "impact_metal_heavy",
"fireproof": "true",
"identifier": "divingsuit",
"description": "",
"tags": "diving,divingsuit,light",
"name": "",
"scale": "0.5"
}
},
"underwaterscooter": {
"Attrs": {
"category": "Equipment",
"impactsoundtag": "impact_metal_light",
"identifier": "underwaterscooter",
"cargocontaineridentifier": "metalcrate",
"isshootable": "true",
"Tags": "smallitem,provocative,light",
"name": "",
"description": "",
"Scale": "0.32"
}
},
"oxygenitetank": {
"Attrs": {
"category": "Equipment,Misc",
"impactsoundtag": "impact_metal_light",
"description": "",
"identifier": "oxygenitetank",
"Tags": "smallitem,oxygensource",
"name": "",
"scale": "0.3"
}
},
"oxygentank": {
"Attrs": {
"category": "Equipment,Misc",
"impactsoundtag": "impact_metal_light",
"identifier": "oxygentank",
"cargocontaineridentifier": "metalcrate",
"Tags": "oxygentank,smallitem,oxygensource",
"name": "",
"scale": "0.3"
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<Items>
<Item name="" identifier="oxygentank" category="Equipment,Misc" Tags="oxygentank,smallitem,oxygensource"
cargocontaineridentifier="metalcrate" scale="0.3" impactsoundtag="impact_metal_light">
<PreferredContainer primary="divingcab" minamount="1" maxamount="5" spawnprobability="1" />
<PreferredContainer primary="oxygengenerator" />
<PreferredContainer primary="divingsuit,divingmask,plasmacutter" spawnprobability="1.0" />
<PreferredContainer primary="supplycab" minamount="1" maxamount="1" spawnprobability="0.5" />
<Price locationtype="Research" buyprice="75" />
<Price locationtype="City" buyprice="75" />
<Price locationtype="Military" buyprice="75" />
<Price locationtype="Outpost" buyprice="70" />
<Deconstruct time="10">
<Item identifier="aluminium" />
</Deconstruct>
<Fabricate suitablefabricators="fabricator" displayname="OxygenTankEmpty" outcondition="0.0">
<RequiredItem identifier="aluminium" />
</Fabricate>
<InventoryIcon texture="Content/Items/InventoryIconAtlas.png" sourcerect="896,0,64,64" origin="0.5,0.5" />
<Sprite texture="Content/Items/Tools/tools_new.png" sourcerect="356,223,39,110" depth="0.55" origin="0.5,0.5" />
<Body width="38" height="109" density="5" />
<Holdable slots="Any,RightHand,LeftHand" holdpos="30,-15" handle1="0,5" handle2="0,-5" msg="ItemMsgPickUpSelect">
<StatusEffect type="OnFire" target="This" Condition="-100.0" disabledeltatime="true">
<Conditional Condition="gt 25" />
<sound file="Content/Items/Weapons/ExplosionSmall1.ogg" range="5000" />
<sound file="Content/Items/Weapons/ExplosionDebris1.ogg" range="5000" />
<Explosion range="250.0" structuredamage="10" force="3.0">
<Affliction identifier="burn" strength="5" />
<Affliction identifier="stun" strength="5" />
</Explosion>
</StatusEffect>
<StatusEffect type="OnFire" target="This" Condition="-100.0" disabledeltatime="true" />
</Holdable>
</Item>
<Item name="" identifier="oxygenitetank" category="Equipment,Misc" Tags="smallitem,oxygensource" description=""
scale="0.3" impactsoundtag="impact_metal_light">
<PreferredContainer primary="oxygengenerator" />
<PreferredContainer primary="oxygentankcontainer" />
<Deconstruct time="10">
<Item identifier="aluminium" />
<Item identifier="liquidoxygenite" mincondition="0.5" />
<Item identifier="liquidoxygenite" mincondition="0.9" />
</Deconstruct>
<Fabricate suitablefabricators="fabricator" outcondition="100.0" requiredtime="5">
<RequiredSkill identifier="mechanical" level="40" />
<RequiredItem identifier="aluminium" />
<RequiredItem identifier="liquidoxygenite" />
<RequiredItem identifier="liquidoxygenite" />
</Fabricate>
<InventoryIcon texture="Content/Items/InventoryIconAtlas.png" sourcerect="319,901,61,61" origin="0.5,0.5" />
<Sprite texture="Content/Items/Tools/tools_new.png" sourcerect="473,223,39,112" depth="0.55" />
<Body width="39" height="112" density="9.9" />
<Holdable slots="Any,RightHand,LeftHand" holdpos="30,-15" handle1="0,5" handle2="0,-5" msg="ItemMsgPickUpSelect">
<StatusEffect type="OnFire" target="This" Condition="-100.0" disabledeltatime="true">
<Conditional Condition="gt 20" />
<sound file="Content/Items/Weapons/ExplosionSmall2.ogg" range="5000" />
<sound file="Content/Items/Weapons/ExplosionDebris2.ogg" range="5000" />
<Explosion range="280.0" structuredamage="20" stun="8" force="3.0">
<Affliction identifier="burn" strength="10" />
</Explosion>
</StatusEffect>
</Holdable>
</Item>
<Item name="" identifier="divingmask" scale="0.5" category="Equipment" Tags="smallitem,diving,divingmask"
cargocontaineridentifier="metalcrate" description="" impactsoundtag="impact_metal_light">
<PreferredContainer primary="divingcab" minamount="1" maxamount="2" spawnprobability="1" />
<PreferredContainer primary="supplycab" minamount="1" maxamount="1" spawnprobability="0.25" />
<Price locationtype="Research" buyprice="55" />
<Price locationtype="City" buyprice="55" />
<Price locationtype="Military" buyprice="55" />
<Price locationtype="Outpost" buyprice="100" />
<Deconstruct time="10">
<Item identifier="plastic" />
<Item identifier="rubber" />
</Deconstruct>
<Fabricate suitablefabricators="fabricator" requiredtime="20">
<RequiredSkill identifier="mechanical" level="25" />
<RequiredItem identifier="plastic" />
<RequiredItem identifier="rubber" />
<RequiredItem identifier="rubber" />
</Fabricate>
<InventoryIcon texture="Content/Items/InventoryIconAtlas.png" sourcerect="515,322,57,62" origin="0.5,0.5" />
<Sprite name="Diving Mask" texture="Content/Items/Jobgear/headgears.png" depth="0.55" sourcerect="226,326,69,68"
origin="0.5,0.5" />
<Body width="26" height="18" density="15" />
<Wearable limbtype="Head" slots="Any,Head" msg="ItemMsgPickUpSelect" displaycontainedstatus="true">
<sprite name="Diving Mask Wearable" texture="Content/Items/Jobgear/headgears.png" limb="Head"
inheritlimbdepth="true" inherittexturescale="true" hidelimb="false" hideotherwearables="false"
sourcerect="226,326,69,68" origin="0.4,0.3" hidewearablesoftype="moustache,beard" />
<StatusEffect type="OnWearing" target="Character" HideFace="true" ObstructVision="true" SpeedMultiplier="0.9"
setvalue="true" disabledeltatime="true" />
<StatusEffect type="OnWearing" target="Contained,Character" OxygenAvailable="1000.0" Condition="-0.5"
comparison="Or">
<Conditional IsDead="false" />
<RequiredItem items="oxygentank" type="Contained" />
</StatusEffect>
<StatusEffect type="OnWearing" target="Contained,Character" OxygenAvailable="-100.0" Oxygen="-5.0"
Condition="-5.0">
<Conditional IsDead="false" />
<RequiredItem items="weldingfueltank" type="Contained" />
</StatusEffect>
<StatusEffect type="OnWearing" target="Contained,Character" OxygenAvailable="-100.0" Oxygen="-7.0"
Condition="-5.0">
<RequiredItem items="incendiumfueltank" type="Contained" />
<Affliction identifier="burn" amount="0.1" />
</StatusEffect>
<StatusEffect type="OnWearing" target="Contained,Character" OxygenAvailable="1000.0" Condition="-0.3"
comparison="Or">
<Conditional IsDead="false" />
<RequiredItem items="oxygeniteshard" type="Contained" />
</StatusEffect>
<StatusEffect type="OnWearing" target="Contained,Character" OxygenAvailable="1500.0" Condition="-0.1"
comparison="Or">
<Conditional IsDead="false" />
<RequiredItem items="oxygenitetank" type="Contained" />
</StatusEffect>
<StatusEffect type="OnWearing" target="Contained,Character" SpeedMultiplier="1.1" setvalue="true" comparison="Or">
<Conditional IsDead="false" />
<RequiredItem items="oxygeniteshard" type="Contained" />
</StatusEffect>
<StatusEffect type="OnWearing" target="Contained,Character" SpeedMultiplier="1.2" setvalue="true" comparison="Or">
<Conditional IsDead="false" />
<RequiredItem items="oxygenitetank" type="Contained" />
</StatusEffect>
</Wearable>
<ItemContainer capacity="1" hideitems="true">
<ContainedStateIndicator texture="Content/UI/ContainerIndicators.png" sourcerect="0,157,92,27" />
<Containable items="oxygensource,weldingfuel" />
</ItemContainer>
</Item>
<Item name="" identifier="divingsuit" category="Equipment" tags="diving,divingsuit,light" scale="0.5" fireproof="true"
description="" impactsoundtag="impact_metal_heavy">
<PreferredContainer primary="divingsuitcontainer" spawnprobability="0.8" />
<Price locationtype="Research" buyprice="225" />
<Price locationtype="City" buyprice="225" />
<Price locationtype="Military" buyprice="225" />
<Price locationtype="Outpost" buyprice="300" />
<Deconstruct time="30">
<Item identifier="aluminium" />
<Item identifier="titanium" />
<Item identifier="rubber" />
</Deconstruct>
<Fabricate suitablefabricators="fabricator" requiredtime="30">
<RequiredSkill identifier="mechanical" level="40" />
<RequiredItem identifier="titaniumaluminiumalloy" />
<RequiredItem identifier="rubber" />
<RequiredItem identifier="rubber" />
</Fabricate>
<InventoryIcon texture="Content/Items/InventoryIconAtlas.png" sourcerect="449,320,63,64" origin="0.5,0.5" />
<!--
<Sprite name="Diving Suit" texture="DivingSuit_Item.png" sourcerect="157,0,90,307" depth="0.55" origin="0.4888889,0.5439739" />
-->
<Sprite name="Diving Suit Item" texture="Content/Items/Containers/DivingSuitLocker.png" sourcerect="331,196,126,112"
depth="0.55" origin="0.5,0.5" />
<ContainedSprite name="Diving Suit In Vertical Locker" allowedcontainertags="divingsuitcontainervertical"
texture="Content/Items/Containers/DivingSuitLocker.png" sourcerect="330,0,71,195" depth="0.55" origin="0.5,0.5" />
<ContainedSprite name="Diving Suit Behind Window" allowedcontainertags="divingsuitcontainerwindow"
texture="Content/Items/Containers/Lockers.png" sourcerect="0,686,99,254" depth="0.55" origin="0.0,0.0" />
<ContainedSprite name="Diving Suit In Horizontal Locker" allowedcontainertags="divingsuitcontainerhorizontal"
texture="Content/Items/Containers/DivingSuitLocker.png" sourcerect="236,340,228,66" depth="0.55"
origin="0.6,0.5" />
<Body radius="45" width="34" density="15" />
<Wearable slots="OuterClothes" msg="ItemMsgEquipSelect" displaycontainedstatus="true">
<sprite name="Diving Suit Helmet Wearable" texture="Content/Items/Jobgear/headgears.png" limb="Head"
inheritlimbdepth="true" inherittexturescale="true" hidelimb="true" hideotherwearables="true"
sourcerect="5,4,92,94" origin="0.5,0.5">
<LightComponent range="200.0" lightcolor="250,224,165,255" powerconsumption="10" IsOn="true">
<StatusEffect type="OnWearing" target="This,Character" Voltage="1.0" setvalue="true">
<Conditional IsDead="false" />
</StatusEffect>
<LightTexture texture="Content/Lights/divinghelmetlight.png" origin="0.05, 0.5" size="1.0,1.0" />
</LightComponent>
</sprite>
<sprite texture="DivingSuit_Torso.png" limb="Torso" inheritlimbdepth="true" hidelimb="true"
hideotherwearables="true" inherittexturescale="true" inheritorigin="true" inheritsourcerect="true" />
<sprite texture="DivingSuit_Legs.png" limb="Waist" inheritlimbdepth="true" hidelimb="true"
hideotherwearables="true" inherittexturescale="true" inheritorigin="true" inheritsourcerect="true" />
<sprite texture="DivingSuit_Torso.png" limb="RightHand" inheritlimbdepth="true" hidelimb="true"
hideotherwearables="true" inherittexturescale="true" inheritorigin="true" inheritsourcerect="true" />
<sprite texture="DivingSuit_Torso.png" limb="LeftHand" inheritlimbdepth="true" hidelimb="true"
hideotherwearables="true" inherittexturescale="true" inheritorigin="true" inheritsourcerect="true" />
<sprite texture="DivingSuit_Torso.png" limb="RightArm" inheritlimbdepth="true" hidelimb="true"
hideotherwearables="true" inherittexturescale="true" inheritorigin="true" inheritsourcerect="true" />
<sprite texture="DivingSuit_Torso.png" limb="LeftArm" inheritlimbdepth="true" hidelimb="true"
hideotherwearables="true" inherittexturescale="true" inheritorigin="true" inheritsourcerect="true" />
<sprite texture="DivingSuit_Legs.png" limb="RightThigh" inheritlimbdepth="true" hidelimb="true"
hideotherwearables="true" inherittexturescale="true" inheritorigin="true" inheritsourcerect="true" />
<sprite texture="DivingSuit_Legs.png" limb="LeftThigh" inheritlimbdepth="true" hidelimb="true"
hideotherwearables="true" inherittexturescale="true" inheritorigin="true" inheritsourcerect="true" />
<sprite texture="DivingSuit_Legs.png" limb="RightLeg" inheritlimbdepth="true" hidelimb="true"
hideotherwearables="true" inherittexturescale="true" inheritorigin="true" inheritsourcerect="true" />
<sprite texture="DivingSuit_Legs.png" limb="LeftLeg" inheritlimbdepth="true" hidelimb="true"
hideotherwearables="true" inherittexturescale="true" inheritorigin="true" inheritsourcerect="true" />
<sprite texture="DivingSuit_Legs.png" limb="RightFoot" sound="footstep_armor_heavy" inheritlimbdepth="true"
hidelimb="true" hideotherwearables="true" inherittexturescale="true" inheritorigin="true"
inheritsourcerect="true" />
<sprite texture="DivingSuit_Legs.png" limb="LeftFoot" sound="footstep_armor_heavy" inheritlimbdepth="true"
hidelimb="true" hideotherwearables="true" inherittexturescale="true" inheritorigin="true"
inheritsourcerect="true" />
<StatusEffect type="OnWearing" target="Character" HideFace="true" ObstructVision="true" PressureProtection="100.0"
SpeedMultiplier="0.6" LowPassMultiplier="0.2" setvalue="true" disabledeltatime="true">
<Sound file="Content/Items/Diving/DivingSuitLoop1.ogg" range="500" />
</StatusEffect>
<StatusEffect type="OnWearing" target="Contained,Character" OxygenAvailable="1000.0" Condition="-0.3"
comparison="Or">
<Conditional IsDead="false" />
<RequiredItem items="oxygentank" type="Contained" />
</StatusEffect>
<StatusEffect type="OnWearing" target="Contained,Character" Oxygen="-20.0" Condition="-0.5">
<Conditional IsDead="false" />
<RequiredItem items="weldingfueltank" type="Contained" />
</StatusEffect>
<StatusEffect type="OnWearing" target="Contained,Character" Oxygen="-20.0" Condition="-0.5">
<Conditional IsDead="false" />
<RequiredItem items="incendiumfueltank" type="Contained" />
<Affliction identifier="burn" amount="0.1" />
</StatusEffect>
<StatusEffect type="OnWearing" target="Contained,Character" OxygenAvailable="1000.0" Condition="-0.3"
comparison="Or">
<Conditional IsDead="false" />
<RequiredItem items="oxygeniteshard" type="Contained" />
</StatusEffect>
<StatusEffect type="OnWearing" target="Contained,Character" OxygenAvailable="1500.0" Condition="-0.1"
comparison="Or">
<Conditional IsDead="false" />
<RequiredItem items="oxygenitetank" type="Contained" />
</StatusEffect>
<StatusEffect type="OnWearing" target="Contained,Character" SpeedMultiplier="1.2" setvalue="true" comparison="Or">
<Conditional IsDead="false" />
<RequiredItem items="oxygeniteshard" type="Contained" />
</StatusEffect>
<StatusEffect type="OnWearing" target="Contained,Character" SpeedMultiplier="1.3" setvalue="true" comparison="Or">
<Conditional IsDead="false" />
<RequiredItem items="oxygenitetank" type="Contained" />
</StatusEffect>
<StatusEffect type="OnWearing" target="Character" OxygenAvailable="-100.0" />
<damagemodifier armorsector="0.0,360.0" afflictionidentifiers="bitewounds,blunttrauma,lacerations,gunshotwound"
damagemultiplier="0.8" damagesound="LimbArmor" deflectprojectiles="true" />
<damagemodifier armorsector="0.0,360.0" afflictiontypes="bleeding" damagemultiplier="0.5"
probabilitymultiplier="0.5" damagesound="LimbArmor" deflectprojectiles="true" />
<damagemodifier armorsector="0.0,360.0" afflictiontypes="burn" damagemultiplier="0.6" damagesound="LimbArmor"
deflectprojectiles="true" />
<damagemodifier armorsector="0.0,360.0" afflictiontypes="radiationsickness" damagemultiplier="0.0"
damagesound="LimbArmor" />
<damagemodifier armorsector="0.0,360.0" afflictiontypes="huskinfection" damagemultiplier="0.5"
probabilitymultiplier="0.5" damagesound="LimbArmor" />
</Wearable>
<ItemContainer capacity="1" hideitems="true">
<ContainedStateIndicator texture="Content/UI/ContainerIndicators.png" sourcerect="0,157,92,27" />
<Containable items="oxygensource,weldingfuel" />
<StatusEffect type="OnWearing" target="Contained">
<RequiredItem items="oxygensource" type="Contained" matchonempty="true" />
<Conditional condition="lt 5.0" />
<Sound file="Content/Items/WarningBeep.ogg" range="500" />
</StatusEffect>
</ItemContainer>
<aitarget maxsightrange="1500" />
</Item>
<Item name="" identifier="underwaterscooter" category="Equipment" Tags="smallitem,provocative,light"
cargocontaineridentifier="metalcrate" description="" Scale="0.32" impactsoundtag="impact_metal_light"
isshootable="true">
<PreferredContainer primary="divingcab" minamount="1" maxamount="3" spawnprobability="1" />
<Price locationtype="Research" buyprice="150" />
<Price locationtype="City" buyprice="150" />
<Price locationtype="Military" buyprice="150" />
<Price locationtype="Outpost" buyprice="200" />
<Deconstruct time="20">
<Item identifier="aluminium" />
<Item identifier="aluminium" />
</Deconstruct>
<Fabricate suitablefabricators="fabricator" requiredtime="30">
<RequiredSkill identifier="mechanical" level="30" />
<RequiredItem identifier="aluminium" />
<RequiredItem identifier="aluminium" />
</Fabricate>
<InventoryIcon texture="Content/Items/InventoryIconAtlas.png" sourcerect="256,128,67,62" origin="0.5,0.5" />
<Sprite texture="Scooter.png" depth="0.55" sourcerect="0,0,219,159" />
<Body width="180" height="95" density="11" />
<Holdable slots="Any,RightHand+LeftHand" aimpos="90,0" handle1="-50,65" handle2="-54,69"
msg="ItemMsgPickUpSelect" />
<Propulsion force="150" usablein="water" particles="bubbles">
<RequiredItems items="mobilebattery" type="Contained" msg="ItemMsgBatteryCellRequired" />
<StatusEffect type="OnUse" target="Contained" Condition="-0.25">
<RequiredItem items="batterycell" type="Contained" />
</StatusEffect>
<StatusEffect type="OnUse" target="Contained" Condition="-0.125">
<RequiredItem items="fulguriumbatterycell" type="Contained" />
</StatusEffect>
<StatusEffect type="OnUse" target="Contained" Condition="-0.25">
<RequiredItem excludedidentifiers="batterycell,fulguriumbatterycell" type="Contained" />
</StatusEffect>
<sound file="Content/Items/Diving/ScooterLoop.ogg" type="OnUse" range="500.0" loop="true" />
<LightComponent LightColor="1.0,1.0,1.0,0.8" range="1000">
<LightTexture texture="Content/Lights/lightcone.png" origin="-0.01, 0.5" size="1.0,1.0" />
</LightComponent>
</Propulsion>
<ItemContainer capacity="1" hideitems="true">
<ContainedStateIndicator texture="Content/UI/ContainerIndicators.png" sourcerect="1,70,107,31" />
<Containable items="mobilebattery" />
</ItemContainer>
<AiTarget soundrange="3000" maxsightrange="3000" />
</Item>
</Items>
$paths = @{
DivingXml = Join-Path $PSScriptRoot -ChildPath 'divinggear.xml'
ExportJson = Join-Path $PSScriptRoot -ChildPath 'divinggear.json'
ExportJsonVerbose = Join-Path $PSScriptRoot -ChildPath 'divinggear-verbose.json'
SampleXmlUrl = 'https://gist.githubusercontent.com/ninmonkey/598473a71ddcd2cc2647ecb690aafd4a/raw/3ed8ab8ca7ff5a9e40ab05c78c8584cc5e77e3be/divinggear.xml'
# './divinggear.xml'
}
$AutoOpenInVsCode = $false
if(! (test-path $paths.DivingXml )) {
if ('y' -ne (Read-Host -Prompt '[y for Yes] download sample.xml ?')) {
throw "file missing, You can download it without cloning at: $($paths.SampleXmlUrl)"
}
Invoke-WebRequest -Uri $paths.SampleXmlUrl -OutFile $paths.DivingXml
}
function hr {
"-" * [console]::WindowWidth
}
<#
Does this look crazy for xml, or is it okay?
Because:
$xml | ConvertTo-Json
outputs stuff like
[
[],
[
[
"System.Xml.XmlElement",
"System.Xml.XmlElement",
"System.Xml.XmlElement",
"System.Xml.XmlElement",
"System.Xml.XmlElement"
]
]
]
#>
function XmlAttributesToHash {
<#
.description
given an XmlElement, returns a hashtable of all attributes
.example
$xml.SelectNodes('/Items/Item') | ForEach-Object {
XmlAttributesToHash $_
} | ConvertTo-Json
#>
[CmdletBinding()]
param (
[Parameter(Mandatory, HelpMessage = "Element or node in Xml doc to fetch attributes")]
[System.Xml.XmlElement]$Element
)
$Attributes = @{}
$Element.Attributes | ForEach-Object {
$Attributes.add( $_.name, $_.Value )
}
$Attributes
}
function ScrapeXmlItems {
param(
[Parameter(Mandatory, Position=0)]
[string]$ExportPath,
[switch]$VerboseExport
)
[xml]$xml = gc $paths.DivingXml -ea 'Stop'
$ItemData = @{}
$xml.SelectNodes('/Items/Item') | ForEach-Object {
$curElement = $_
$Name = $curElement.identifier
$HashValue = @{
Attrs = XmlAttributesToHash $curElement
}
if ($VerboseExport) {
#this exports [hashtable]
$PrefList = $curElement.SelectNodes('PreferredContainer') | ForEach-Object {
$curContainer = $_
XmlAttributesToHash $curContainer
}
$HashValue['PreferredContainer'] = $PrefList
}
$ItemData[ $Name ] = $HashValue
}
$ItemData | ConvertTo-Json | Out-File $ExportPath
'Found {0} items' -f $ItemData.Count
}
# Main entry point
ScrapeXmlItems $paths.ExportJson
ScrapeXmlItems $paths.ExportJsonVerbose -VerboseExport
if ($AutoOpenInVsCode) {
code $paths.ExportJson
code $paths.ExportJsonVerbose
} else {
Get-Content $paths.ExportJson
hr
Get-Content $paths.ExportJsonVerbose
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment