JSON to XML conversion not working

I am trying to convert JSON to XML using newtonsoft, but since the left side contains a number and XML cannot have an element that starts with the number that the conversion occurs with

Example:

{
   "PLC": {
       "10": 7.6,
       "9": 1.8,
       "4": 11
      }
}

      

Is there a safe conversion anyway? or force it to prefix "_", for example, to items that start with a number?

+3


source to share


1 answer


Obviously, there is no general way to safely transform it. XML element and attribute names cannot start with a digit. If you use tricks such as appending _

to an element name or introducing special elements into a special namespace (for example <atikot:item id="10">7.6</atikot:item>

) to express this construct, you are losing generality and you need special handling for reverse transform, XML serialization, and deserialization. You may also have problems with DTDs if you use them. First, you must ask yourself what kind of XML you want after transformation and what it will be used for.



+1


source







All Articles