I have some sample JSON on this format:
{
"id": "532-513jg-5ujkl-5jiklf",
"externalGuid": "93804jlkfes",
"tagNumber": "2KMA",
"project": {
"id": "532kg-fw13jg-553klal-5jiklf",
"projectName": "Test",
"projectId": "1"
},
"properties": [
{
"id": "jkl39-jkl39084-agd208-hh82a9",
"name": "Weight",
"value": "1000",
"statusCode": {
"name": "Accepted",
"code": 1
}
},
{
"id": "jkl39-jkl384-123208-hh82a9",
"name": "Length",
"value": "10",
"statusCode": {
"name": "Not Accepted",
"code": 3
}
}
]
}
I want to convert this to XML so I do the following:
XmlDocument node = JsonConvert.DeserializeXmlNode(jsonString, "tag");
Which gives me the following XML:
<tag>
<id>532-513jg-5ujkl-5jiklf</id>
<externalGuid>93804jlkfes</comosUID>
<tagNumber>2KMA</tagNumber>
<project>
<id>532kg-fw13jg-553klal-5jiklf</id>
<projectName>Test</projectName>
<projectId>1</projectId>
</project>
<properties>
<id>jkl39-jkl39084-agd208-hh82a9</id>
<name>Weight</name>
<value>1000</value>
<statusCode>
<name>Accepted</name>
<code>1</code>
</statusCode>
<properties>
<id>jkl39-jkl384-123208-hh82a9</id>
<name>Length</name>
<value>10</value>
<statusCode>
<name>Not Accepted</name>
<code>3</code>
</statusCode>
</properties>
</tag>
which is ALMOST what I want. However the system that is going to import the XML expects a slightly different format. It wants each of the properties to start and end with a <property> tag. So the properties array would look like this:
<properties>
<property>
<id>jkl39-jkl39084-agd208-hh82a9</id>
<name>Weight</name>
<value>1000</value>
<statusCode>
<name>Accepted</name>
<code>1</code>
</statusCode>
</property>
<property>
<id>jkl39-jkl384-123208-hh82a9</id>
<name>Length</name>
<value>10</value>
<statusCode>
<name>Not Accepted</name>
<code>3</code>
</statusCode>
</property>
</properties>
How can I make the XML match this template? That is, replace the properties tags with property, and wrap all the property tags in a properties parent tag.