Need to extract table using regex in XML

Hi,
I have two xml files which are mentioned below.

XML File 1

XML File 2

Now, in both xml files I need to search for two specific strings which are actually headings of table, for the first file it is “B. III.1. Bruttorückstellung für noch nicht abgewickelte Versicherungsfälle” and for the second file it is “C. II. 1. Bruttorückstellung für noch nicht abgewickelte Versicherungsfalle” and after searching it, I need to extract the table below (which you can see in the both images).

I tried with xml parsing using query, for one file it’s possible but for several files the “xml parsing query” is not working as the query is not dynamic one. As you can see in the both images the ascending xml tags for the headings (searched strings) are different (first file’s searched string has tag whereas the second file has only) so, the query does not work in both.

Is there any possibility I can use regex over here to extract the table below of the heading (with the help of the searched strings) ? What will be regex in that case ?

Any suggestion will be very helpful.

Thanks.

when adopting the past solution approach we maybe can anchor more only on the element value (C II…) instead within a combination with the element name.

Can you share a sample XML for this second case? Thanks

1 Like

Ok Perfect, just give me a little time. I will have a look on it

It is experimental, but can you please check:

xDoc.Descendants("TABLE").Where(Function (x) x.ElementsBeforeSelf().Last().Value.Trim.StartsWith("C. II")).First()

should work for both XML

1 Like

Hi

please try below vb script to convert XML file to datatable.

Dim myDS As New DataSet
myDS.ReadXml(New StringReader(XMLText.ToString))
Console.WriteLine(myDS.Tables.Count)
resDataTable=myDS.Tables(0)

XMLText in parameter
resDataTable out Parameter DataTable

1 Like

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