At this moment I'm struggling to deserialize an XML response from BRO ( part of the Dutch government). They have a public API that can be used to get groundwater levels and details. This is the response( url ).
If I change this part xsi:type="ns11:GLD_O_DPType"
with string.replace the XML can be parsed.
From:
<ns11:GLD_O xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns11:GLD_O_DPType" gml:id="BRO_0002">
To:
<ns11:GLD_O xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" gml:id="BRO_0002">
The XML container class is created true my IDE Visual Studio 2022 via Edit > paste Special > Paste XML As Classes. And this is the generated class
The following code is used to deserialize the XML:
public static T ParseXML<T>(this string @this) where T : class
{
if(@this == null) { return null; }
var reader = XmlReader.Create(@this.Trim().ToStream(), new XmlReaderSettings() { ConformanceLevel = ConformanceLevel.Document });
return new XmlSerializer(typeof(T)).Deserialize(reader) as T;
}
// In my mainclass
var parsedResult = ParseHelpers.ParseXML<dispatchDataResponse>(result);
In my mainclass, result is a type of string from the response body of the request (first link)
In short, how can I deserialize the object with the attribute xmlns:xsi