I want to retrieve a list of array from XML file. I use an integration tool for querying. But what should I do if I want to create a list of arrays without any foreach loop. (Reason is, in this case foreach cannot be applied.
XML File Format:
<arr name="ArrayinXML"><str>dsfadasfsdasda</str><str>gdhsdhshhfb</str>
In Index.cshtml:
@p.ArrayinXML.FirstOrDefault()
In the above case, it returns only the first string value and not the second one.
Can you make an extension method that does the foreach for you?
Something like this:
You could, of course, just call
@String.Join(p.ArrayinXML, ", ")in your code, but I think the extension method makes it a bit more elegant.Then add the extension namespace to your web.config, and you can do this in the view:
Edit:
Here’s the extension with a transform parameter so you can customize further: