Created
June 23, 2021 11:17
-
-
Save mgravell/c649229a7e3b2aaf906dc905c904f15b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Xml.Serialization; | |
static class P | |
{ | |
static void Main() | |
{ | |
var xml = @"<ABRPayloadSearchResults xmlns:xsd=""w3.org/2001/XMLSchema"" xmlns:xsi=""w3.org/2001/XMLSchema-instance"" xmlns=""abr.business.gov.au/ABRXMLSearch""> <response> <abnList> <numberOfRecords>2680</numberOfRecords> <abn>95437472757</abn> <abn>38023383928</abn> <abn>12839919648</abn> <abn>50165055391</abn> <abn>60306167177</abn> </abnList> </response> </ABRPayloadSearchResults>"; | |
var ser = new XmlSerializer(typeof(Root)); | |
var root = (Root)ser.Deserialize(new StringReader(xml)); | |
var response = root.Response; | |
var carList = response.AbnList; | |
Console.WriteLine(carList.NumberOfRecords); | |
if (carList.Items is not null) | |
{ | |
foreach (var abn in carList.Items) | |
{ | |
Console.WriteLine(abn); | |
} | |
} | |
} | |
} | |
[XmlRoot("ABRPayloadSearchResults", Namespace = "abr.business.gov.au/ABRXMLSearch")] | |
public class Root | |
{ | |
[XmlElement("response")] | |
public Response Response { get; set; } | |
} | |
public class Response | |
{ | |
[XmlElement("abnList")] | |
public AbnList? AbnList { get; set; } | |
} | |
public class AbnList | |
{ | |
[XmlElement("numberOfRecords")] | |
public int? NumberOfRecords { get; set; } | |
[XmlElement("abn")] | |
public List<string>? Items { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment