I have an XML file that looks like this
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="application" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="Parameter1" Value="test1" />
<Parameter Name="parameter2" Value="test2" />
<Parameter Name="parameter3" Value="test3" />
<Parameter Name="parameter4" Value="test4" />
</Parameters>
</Application>
I am using a hashtable to convert this to JSON but when I do, I only get the Parameters portion:
{
"PARAMETER_1": "Test",
"parameter2" : "test2"
I'm Reading the xml file like so because if i try to read it as $appParametersXml then I get an error.
$appParametersHashTable = Read-XmlElementAsHashtable $appParametersXml.Application.Parameters
$appParametersHashTable |ConvertTo-Json |Out-File "C:\Workspaces\ARMTemplates\GhostDraftApplication\ARMTemplate\CloudAXF.json"
#$appParametersHashTable|ConvertFrom-Xml|Out-File "C:\Workspaces\ARMTemplates\GhostDraftApplication\ARMTemplate\CloudTest.xml"
$appParametersXml | ConvertFrom-Xml | ConvertTo-Json -Depth 4 | Out-File "C:\Workspaces\ARMTemplates\GhostDraftApplication\ARMTemplate\CloudAXF.json"
$xmlObject = $appParametersXml | ConvertTo-Xml
###############################################################################
function Read-XmlElementAsHashtable
{
Param (
[System.Xml.XmlElement]
$Element
)
$hashtable = @{}
if ($Element.ChildNodes)
{
$Element.ChildNodes |
ForEach-Object {
$hashtable["Name" + $_.Name] = "Value" + $_.Value
}
}
return $hashtable
}
Is there a way to read the all the tags and attributes from the xml file and convert them to JSON so it looks like this?
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"PARAMETER_1": {
"value": "Test"
},
I've just been spinning my wheels.