So the other day I asked this question and got pointed to this question which got me part way through my issues.
My original data example was reduced and simplified to get my initial issue solved but in the process of finally being able to deserialize the xml into my classes I noticed that about 10 objects into the deserialization it would error out. After some trouble shooting I played with the data to find the actual and it appears that the <b></b>
within the <p></p>
is my issue. I have used a couple of converters online to help with my classes but none seem to properly resolve that issue.
There are a ton of XML tags prior to this in various hierarchies...
<description type="formattedtext">
<p>Some stuff in here.</p>
<p>Some other stuff was here.</p>
<p><b>Title of Table</b></p>
<table>
<tr>
<td><b>Size</b></td>
<td><b>weight</b></td>
<td><b>Length</b></td>
</tr>
<tr>
<td>Tiny</td>
<td>20</td>
<td>18</td>
</tr>
<tr>
<td>Small</td>
<td>25</td>
<td>16</td>
</tr>
<tr>
<td>Medium</td>
<td>40</td>
<td>13</td>
</tr>
<tr>
<td>Large</td>
<td>50</td>
<td>10</td>
</tr>
<tr>
<td>Huge</td>
<td>80</td>
<td>10</td>
</tr>
</table>
<p>Some extra description goes here.</p>
<p>Some other extra stuff for describing things goes here.</p>
<p><b>Additional notes. </b>Final stuff goes here.</p>
</description>
There are a lot of XML tags after this in various hierarchies...
I think the real issue is that last bit with the "additional notes" where the <b>
tag is apart of the <p>
but it also has text in it. The deserializer treats all the tags normally associated as HTML as XML so I have classes set up for the table.
All the rest of the classes work but the output for these from the online converters were as follows:
[XmlRoot(ElementName="p")]
public class P {
[XmlElement(ElementName="b")]
public string B { get; set; }
}
[XmlRoot(ElementName="description")]
public class Description {
[XmlElement(ElementName="p")]
public List<string> P { get; set; }
[XmlAttribute(AttributeName="type")]
public string Type { get; set; }
[XmlText]
public string Text { get; set; }
}
I would assume that I need to make the List<string> P
into a List<P> P
but not sure what other property would be necessary, I did try to add a Text like in the Description parent but no joy on the stick.
Also if there is a way to just ignore the structure under an element that could be helpful. As far as I am concerned I don't need to have the array of P under description in its own object it could be a string but I have not found a setting/decorator that would allow that and I assume there might be an issue with the deserializer on the tags underneath so unsure out to escape them to have that be ignored.
The overall purpose is that this data is consumed by an application and within that application I have the ability to add more functionality within the element manually through the UI which translates to additional elements in the XML storage. However, since there are hundreds of these from a half dozen files I am trying to load all the pertinent items and parse them then output into a new data file for consumption by the program with the UI.