I have here a variable string named OutputKSZ, containing the code of a XML file. The code of this XML file will contain variable amounts of the tag <streetName language = "EN">
followed by a totally variable street name, and then </streetName>
.
Now, I also have a winforms tiny application, with one textbox, one button and one combobox. In the textbox, I copypaste the XML code. Then I click the button, and the combobox should give me a list of all the different street names between each <streetName language = "EN"></streetName>
tag.
So, for all clarity, there's two variable things here:
- the amount of occurrences of the tag
streetName
- the length of each string between each
streetName
tag.
This is what I've tried so far:
if (OutputKSZ.Contains("<address source=\""))
{
// LIJST MET START INDEXES
List<int> indexesStart = new List<int>();
var AddressSourceStart = new Regex("<streetName language=\"EN\">");
foreach (Match match in AddressSourceStart.Matches(OutputKSZ))
{ indexesStart.Add(match.Index); }
// LIJST MET END INDEXES
List<int> indexesEnd = new List<int>();
var AddressSourceEnd = new Regex("</streetName>");
foreach (Match match in AddressSourceEnd.Matches(OutputKSZ))
{ indexesEnd.Add(match.Index); }
int[] counterI = Enumerable.Range(0, indexesStart.Count).ToArray();
foreach (int i in counterI)
{
int KSZGedeelteStraatStart = indexesStart[i];
int KSZGedeelteStraatEnd = indexesEnd[i];
int KSZGedeelteStraatLength = KSZGedeelteStraatEnd - KSZGedeelteStraatStart - 26;
string KSZGedeelteStraat = OutputKSZ.Substring(KSZGedeelteStraatStart + 26, KSZGedeelteStraatLength);
foreach (int ListCounter in counterI)
{
List<string> ListKSZGedeelteStraat = new List<string>();
ListKSZGedeelteStraat.Add(KSZGedeelteStraat);
comboBox2.DataSource = ListKSZGedeelteStraat;
}
}
Sorry for the Dutch in there. ;)
The problem with this code is that it only displays the very last occurrence, and I'm really fresh out of ideas, I've been at this for hours.
Have you guys any ideas on how to correct this? I'm rather new to c# so as long as I get to keep the textbox, button and combobox, you can rewrite my whole code if need be.
Sample XML:
<soapenv:Envelope>
<s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" />
<soapenv:Body>
<external:searchPersonInformationHistoryBySsinResponse>
<informationCustomer>
<customerIdentification>
<sector>15</sector>
<institution>5</institution>
</customerIdentification>
</informationCustomer>
<informationCBSS>
<ticketCBSS>b2d07603-2205-4258-b3b9-49320ab4b919</ticketCBSS>
<timestampReceive>2016-03-27T12:49:59.680Z</timestampReceive>
<timestampReply>2016-03-27T12:50:00.072Z</timestampReply>
</informationCBSS>
<legalContext>NISSE:IDENTIFICATION</legalContext>
<criteria>
<ssin>somenumber</ssin>
<datagroups>
<addresses>true</addresses>
</datagroups>
</criteria>
<status>
<value>DATA_FOUND</value>
<code>MSG00000</code>
<description>Successful</description>
</status>
<result>
<person register="RR">
<ssin>somenumber</ssin>
<addresses status="DATA_FOUND">
<address source="NR">
<residentialAddress>
<countryCode>150</countryCode>
<countryName language="FR">Belgique</countryName>
<countryName language="NL">België</countryName>
<countryName language="DE">Belgien</countryName>
<cityCode>somecitycode</cityCode>
<cityName language="NL">somecityname</cityName>
<postalCode>somepostalcode</postalCode>
<streetCode>somestreetcode</streetCode>
<streetName language="NL">somestreetname</streetName>
<houseNumber>2</houseNumber>
<inceptionDate>2014-08-09</inceptionDate>
</residentialAddress>
</address>
<address source="NR">
<residentialAddress>
<countryCode>150</countryCode>
<countryName language="FR">Belgique</countryName>
<countryName language="NL">België</countryName>
<countryName language="DE">Belgien</countryName>
<cityCode>someothercitycode</cityCode>
<cityName language="NL">someothercityname</cityName>
<postalCode>someotherpostalcode</postalCode>
<streetCode>someotherstreetcode</streetCode>
<streetName language="NL">someotherstreetname</streetName>
<houseNumber>2</houseNumber>
<inceptionDate>2014-08-09</inceptionDate>
</residentialAddress>
</address>
</addresses>
</person>
</result>
</external:searchPersonInformationHistoryBySsinResponse>
</soapenv:Body>
</soapenv:Envelope>