I have an xml which looks like this
<Planets>
<Planet>
<Name Units="days" Order="1">
<Lists>
<List Units="nights">list_ends_here</List>
</Lists>
</Name>
</Planet>
</Planets>
If Units
attribute has different values like shown here, The code has an error. I am getting the error, but I wanted to report the line number where the error occurs. I have different xmls where Units
has different values so line numbers are different.
The code where I load the xml document
XDocument xdoc = XDocument.Load(file, LoadOptions.SetLineInfo);
IEnumerable<XElement> planets = xdoc.Root.Descendants("Name");
foreach (XElement category in categories)
{
//get line number for element
string lineNumber = ((IXmlLineInfo)category).HasLineInfo() ? ((IXmlLineInfo)category).LineNumber : -1;
}
The way I parse these from the xml:
foreach(XElement pl_name in planets)
{
string Units = pl_name.Attribute("Units").Value;
string units_on_list = pl_name.Descendants("Lists").Elements("List").Select(x => (string)x.Attribute("Units")).ToList()
}
LoadOptions.SetLineInfo
is not giving me the line number