How to parse XElement
as case insensitive ?
Here is my code:
private void GetMyLayer(XElement myElement)
{
Layer layer = new Layer();
foreach (var myItem in myElement.Descendants("layeritem"))
{
if (myItem.Element("HyperLinkFields") != null)
layer.ClickableHyperLinkFields = gisItem.Element("HyperLinkFields").Value.Split(',');
}
}
This is working fine when myItem
contains a field called HyperLinkFields
, but when the field name is HyperlinkFields
can't figure out how to do it as case insensitive manner.
Xml
is case sensitive, one could have element with same name but different case, which is perfectly valid.
If you read the documentation, Element
method returns first (in document order) child element with the specified XName
, so you could play with custom code and achieve the same behavior.
var element = myItem.Elements()
.FirstOrDefault(x=>x.Name.LocalName.Equals(searchstring, StringComparison.OrdinalIgnoreCase));
if(element != null)
{
// Your logic
//layer.ClickableHyperLinkFields = element.Value.Split(',');
}