How can I convert an xml to a datatable?

Hello guys,

I have an xml output from a web service.
How can i convert these fields of xml to my datatable.
Let me show you my xml.

XML:
image

I want these PERNR, EANAME and other fields to be columns of my table.
Can anyone help me?

Thanks,

One of many options:

  • prepare an empty DataTable with build datatable
  • loop over the item elements
  • extract the fields and add all to the datatable

As it is soap have a look here on how to handle XML Namespaces

When needed we can also highly dynamize the datatable preparation and population

1 Like

@mazlumkacar

1.Build a empty datatable with required columns

2.>assign: XDoc=XDocument.Load(“pass the path of .xml file”)
(XDoc datatape as XDocument)

3.>assign:dt_Output=(
From el In XDoc.Descendants(“ARCHER_DATA”)
Let PERNR=CStr(el.Attribute(“id”))
Let ENAME=CStr(el.Element(“author”))
Let LOGON=CStr(el.Element(“title”))
Let VORNA=CStr(el.Element(“price”))
Let NACHN=CStr(el.Element(“publish_date”))
Select Out_Dt.Rows.Add({ColumnName1,ColumnName2,… })
).copyToDataTable

Based on build_datatable mention the ColumnNames in above Syntax
attached sample .xml convert to datatable

Cheers!!

here is my solution.

ASSIGN
OutputFields = DeserializedJsonOutputBody(“ARCHER_DATA”)(“item”)

FOR EACH
ASSIGN
io_OutputDT.Rows(RowCounter)(Column.ColumnName) = JToken(Column.ColumnName).ToString

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