0

I have a problem with my XML Reading file.

XDocument xdoc;
        if (customStyle)
        {
           xdoc = XDocument.Load(@"E:\test-doc.xml");
        }
        else
        {
           xdoc = XDocument.Load(@"E:\ieee-doc.xml");
        }

        Dictionary<string, FormatStyles> customeStylesDic = new Dictionary<string, FormatStyles>();

        xdoc.Descendants("Title").Select(t => new
        {

            fontType = t.Element("fontType").Value,

            fontSize = t.Element("fontSize").Value,

            Underline = t.Element("Underline").Value,

            Bold = t.Element("Bold").Value,

            Italic = t.Element("Italic").Value,

            Alignment = t.Element("Alignment").Value,
        }).ToList().ForEach(t =>
        {
            FormatStyles formatStyle = new FormatStyles();
            string style = "Title";
            formatStyle.CustomFontType = t.fontType;
            formatStyle.CustomFontSize = t.fontSize;
            formatStyle.CustomisBold = Convert.ToBoolean(t.Bold);
            formatStyle.CustomisItalic = Convert.ToBoolean(t.Italic);
            formatStyle.CutomisUnderline = Convert.ToBoolean(t.Underline);
            formatStyle.Cutomalignment = t.Alignment;


            customeStylesDic.Add(style, formatStyle);


        });

Here I try to read XML file using LINQ and pass this values to FormatStyles class, It gives NullReferenceException. But I can't find the error. Can any one help me..

This is my XML file

    <Styles>
    <Title>
    <fontType>Times New Roman</fontType> 
    <fontSize>20</fontSize> 
    <Bold>true</Bold> 
    <Underline>false</Underline> 
    <Italic>true</Italic> 
    <Alingment>center</Alingment> 
    </Title>
    </Styles>
Lasa
  • 75
  • 1
  • 1
  • 6

0 Answers0