Parse XML into datatable

Hi,

I have the following xml output.

I want to convert that into a data table with 2 columns “PhoneNumber” and “Status” for all message headers without using for each.

Please let me know if anybody has a solution.

Thanks,
Amrutha

Hi,

Can you share your xml file as attachment?

Regards,

@ammohan
Kindly note, the XML is defining namespaces, which will be handled as described here:

As mentioned by @Yoichi when the XML sample file is shared, we can help with more details when there are more open questions

Hi,

The following will work, if input xml file is same as yours.

dtResult = xDoc.Descendants(xns+"messageheader").Select(Function(x) dtResult.LoadDataRow({x.Element(xns+"to").Element(xns+"phonenumber").Value,x.Element(xns+"status").Value},False)).CopyToDataTable()

Sample20221211-3aL.zip (3.3 KB)

Regards,

Thanks @Yoichi. The solution you provided gives the desired result.

Regards,
Amrutha