How to unmarshal dynamic XML data to struct?

Hello,

I have a xml data which has some repeated data with dynamic element name as shown below.

<Ht>
	<Criteria>
		<ADNode_1>2</ADNode_1>
		<CDNode_1>2</CDNode_1>
		<IFNode_1>0</IFNode_1>
		<ADNode_2>2</ADNode_2>
		<CDNode_2>0</CDNode_2>
		<IFNode_2>0</IFNode_2>
		<ADNode_3>0</ADNode_3>
		<CDNode_3>0</CDNode_3>
		<IFNode_3>0</IFNode_3>
	</Criteria>
	<session id="1056134770841202228344907">
		<Htd ID="21170">
			<Data_1>
				<Info Count="2"></Info>
				<Data Id="iV29308/B2/R1">
					<Type>TR1</Type>
				</Data>
				<Data Id="iV29308/B3/R1">
					<Type>TR1</Type>
				</Data>
				<Data Id="iV29308/B4/R1">
					<Type>TR1</Type>
				</Data>
				<Data Id="iV29308/B6/R1">
					<Type>TR1</Type>
				</Data>
			</Data_1>
			<Data_2>
				<Info Count="2"></Info>
				<Data Id="iV29308/B2/R1">
					<Type>TR2</Type>
				</Data>
				<Data Id="iV29308/B3/R1">
					<Type>TR2</Type>
				</Data>
				<Data Id="iV29308/B4/R1">
					<Type>TR2</Type>
				</Data>
				<Data Id="iV29308/B6/R1">
					<Type>TR3</Type>
				</Data>
			</Data_2>
		</Htd>
	</session>
</Ht>

I can create indivicual structs for <ADNode_1> ,<ADNode_2> and <ADNode_3> or <Data_1>, <Data_2> but there can be n number of these nodes.
Like below

<ADNode_1>2</ADNode_1>
<ADNode_2>2</ADNode_2>
<ADNode_3>2</ADNode_3>
.
.
<ADNode_n>2</ADNode_n>

or

<Data_1></Data_1>
<Data_2></Data_2>
<Data_3></Data_3>
.
.
.
<Data_n></Data_n>

How can I create struct for these nodes to have n number of nodes or elements?

Here is the playground link

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.