|
| 1 | +--- |
| 2 | +title: "Convert Structure To Xml" |
| 3 | +linkTitle: "Convert Structure To Xml" |
| 4 | +description: "Converts a Structure To Xml." |
| 5 | +--- |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +# {{< param title >}} |
| 10 | + |
| 11 | +<p class="namespace">(Cortex.Blocks.Xml.ConvertXml.ConvertStructureToXmlBlock)</p> |
| 12 | + |
| 13 | +## Description |
| 14 | + |
| 15 | +Converts a [Structure][Structure Property] to [Xml][Json Property]. |
| 16 | + |
| 17 | +## Examples |
| 18 | + |
| 19 | +### Convert a Structure to Xml |
| 20 | + |
| 21 | +This example will convert `TODO` to its Xml representation. |
| 22 | + |
| 23 | +#### Properties |
| 24 | + |
| 25 | +| Property | Value | Notes | |
| 26 | +|--------------------|---------------------------|------------------------------------------| |
| 27 | +| [Structure][Structure Property] | `($)Structure`, with value `{TODO}` | `($)Structure` is a variable of type [Structure][] | |
| 28 | +| [Xml][Xml Property] | `($)Xml`, with no value | `($)Xml` is a variable that will be set to a [String][] value. | |
| 29 | + |
| 30 | +#### Result |
| 31 | + |
| 32 | +Converting `{TODO}` to Xml results in the variable `($)Xml` being updated to the following: |
| 33 | + |
| 34 | +```json |
| 35 | +"TODO" |
| 36 | +``` |
| 37 | + |
| 38 | +Explain how conversion works? |
| 39 | + |
| 40 | +*** |
| 41 | + |
| 42 | +### TODO Different examples |
| 43 | + |
| 44 | +TODO |
| 45 | + |
| 46 | +#### Properties |
| 47 | + |
| 48 | +| Property | Value | Notes | |
| 49 | +|--------------------|---------------------------|------------------------------------------| |
| 50 | +| [Structure][Structure Property] | `($)Structure`, with value `{TODO}` | `($)Structure` is a variable of type [Structure][] | |
| 51 | +| [Xml][Xml Property] | `($)Xml`, with no value | `($)Xml` is a variable that will be set to a [String][] value. | |
| 52 | + |
| 53 | +#### Result |
| 54 | + |
| 55 | +TODO |
| 56 | + |
| 57 | +```json |
| 58 | +TODO |
| 59 | +``` |
| 60 | + |
| 61 | +*** |
| 62 | + |
| 63 | +## Properties |
| 64 | + |
| 65 | +### Structure |
| 66 | + |
| 67 | +The [Structure][Structure Property] to convert to [Xml][Xml Property]. |
| 68 | + |
| 69 | +TODO |
| 70 | + |
| 71 | +| | | |
| 72 | +|--------------------|---------------------------| |
| 73 | +| Data Type | [Structure][] | |
| 74 | +| Property Type | [Input][] | |
| 75 | +| Default Value | `($)Structure` with value `null` | |
| 76 | + |
| 77 | +### Xml |
| 78 | + |
| 79 | +The [Xml][Xml Property] that has been converted from the [Structure][Structure Property]. |
| 80 | + |
| 81 | +TODO |
| 82 | + |
| 83 | +| | | |
| 84 | +|--------------------|---------------------------| |
| 85 | +| Data Type | [String][] | |
| 86 | +| Property Type | [Output][] | |
| 87 | +| Default Value | `($)Xml` with no value | |
| 88 | + |
| 89 | +## Exceptions |
| 90 | + |
| 91 | +The exceptions thrown by the block can be found below: |
| 92 | + |
| 93 | +| Name | Description | |
| 94 | +|----------|----------| |
| 95 | +| [PropertyEmptyException][] | Thrown when [Structure][Structure Property] does not contain any items. | |
| 96 | +| [PropertyNullException][] | Thrown when [Structure][Structure Property] is `null`. | |
| 97 | +| [XmlSerializationException][] | Thrown when [Structure][Structure Property] has a key that is an empty string. | |
| 98 | + |
| 99 | +## Remarks |
| 100 | + |
| 101 | +### Round-tripping |
| 102 | + |
| 103 | +It should be possible to pass the Xml created by this block to the [Convert Xml To Structure][] block, and then pass the [Structure][Structure Property] created by the [Convert Xml To Structure][] block back to this block; this is called round-tripping. |
| 104 | + |
| 105 | +[Structure Property]: {{< ref "#structure" >}} |
| 106 | +[Xml Property]: {{< ref "#xml" >}} |
| 107 | + |
| 108 | +[Input]: {{< url "Cortex.Reference.Concepts.PropertyType.Input" >}} |
| 109 | +[Output]: {{< url "Cortex.Reference.Concepts.PropertyType.Output" >}} |
| 110 | + |
| 111 | +[PropertyEmptyException]: {{< url "Cortex.Reference.Exceptions.Common.Property.PropertyEmptyException.MainDoc" >}} |
| 112 | +[PropertyNullException]: {{< url "Cortex.Reference.Exceptions.Common.Property.PropertyNullException.MainDoc" >}} |
| 113 | +[XmlSerializationException]: {{< url "JsonDotNet.XmlSerializationException" >}} |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | +[Structure]: {{< url "Cortex.Reference.DataTypes.MostCommon.Structure" >}} |
| 118 | +[String]: {{< url "Cortex.Reference.DataTypes.MostCommon.String" >}} |
| 119 | + |
| 120 | + |
| 121 | + /// If there are multiple items in the specified structure, a root node is automatically added to make it valid xml (added root node: "Cortex_FlowEngine_Core_Types_Structure") |
| 122 | + |
| 123 | + /// If a node requires an attribute, use a key value pair where the key is the attribute name with an "@" before it and the value is the attribute data. |
| 124 | + |
| 125 | + /// If data does not require nodes and is within the same element as data that does require nodes, use a key value pair where the key is "#text" and the value is the node-less data. |
| 126 | + |
| 127 | + /// If multiple of the same nodes are required are within the same element, use a key value pair where the key is the node and the value is a list with the nodes data. |
| 128 | + |
| 129 | + /// If the specified structure includes an ampersand symbol in a node's name, the xml will return with "_x0026_" in place of the ampersand symbol. |
| 130 | + |
| 131 | + /// If the specified structure includes an ampersand symbol in a node's data, the xml will return with "&" in place of the ampersand symbol. |
| 132 | + |
| 133 | + |
| 134 | + /// </remarks> |
| 135 | + |
| 136 | + /// <example> |
| 137 | + /// structure: { |
| 138 | + /// "msg&": { |
| 139 | + /// "@attr" : "exampleAttribute" |
| 140 | + /// "id" : |
| 141 | + /// [ |
| 142 | + /// "1", |
| 143 | + /// "2", |
| 144 | + /// "3" |
| 145 | + /// ], |
| 146 | + /// "action" : "stop&" |
| 147 | + /// "#text" : "hello" |
| 148 | + /// } |
| 149 | + /// } |
| 150 | + /// |
| 151 | + /// xml: "<msg_x0026_ attr="exampleAttribute"><id>1</id><id>2</id><id>3</id><action>stop&</action>hello</msg_x0026_>" |
| 152 | + /// </example> |
| 153 | + /// <example> |
| 154 | + /// structure: { |
| 155 | + /// { |
| 156 | + /// "id" : "1" |
| 157 | + /// }, |
| 158 | + /// { |
| 159 | + /// "id2" : "2" |
| 160 | + /// }, |
| 161 | + /// { |
| 162 | + /// "id3" : "3" |
| 163 | + /// } |
| 164 | + /// } |
| 165 | + /// |
| 166 | + /// xml: "<Cortex_FlowEngine_Core_Types_Structure><id>1</id><id2>2</id2><id3>3</id3></Cortex_FlowEngine_Core_Types_Structure>" |
| 167 | + /// </example> |
| 168 | + void ConvertStructureToXml(Structure structure, out string xml); |
0 commit comments