コード例 #1
0
        public static OutlineDocument Load(string fileName)
        {
            var xmlDocument         = XDocument.Load(fileName);
            var thisOutlineDocument = OutlineDocument.CreateFromXmlDocument(xmlDocument);

            thisOutlineDocument.FileName = fileName;
            thisOutlineDocument.State    = OutlineDocumentState.LoadedDocument;

            return(thisOutlineDocument);
        }
コード例 #2
0
        public static OutlineDocument CreateFromXmlElement(XElement xmlElement)
        {
            if (xmlElement == null)
            {
                throw new ArgumentNullException(nameof(xmlElement));
            }

            if (xmlElement.Name != "SimpleOutlineDocument")
            {
                throw new DecodingException();
            }

            if (xmlElement.Attributes().Count() > 0)
            {
                throw new DecodingException();
            }

            if (xmlElement.Elements().SingleOrDefault(e => e.Name != "Outline") != null)
            {
                throw new DecodingException();
            }

            if (xmlElement.Elements().SingleOrDefault(e => e.Name == "Outline") == null)
            {
                throw new DecodingException();
            }

            var xmlOutlineElement = xmlElement.Element("Outline");

            if (xmlOutlineElement.Attributes().Count() > 0)
            {
                throw new DecodingException();
            }

            if (xmlOutlineElement.Elements("Item").Count() != 1)
            {
                throw new DecodingException();
            }

            var thisOutlineDocument = new OutlineDocument();

            var rootItemXmlElement = xmlOutlineElement.Element("Item");
            var rootOutlineItem    = OutlineItem.CreateFromXmlElement(rootItemXmlElement);

            thisOutlineDocument.Items[0] = rootOutlineItem;

            return(thisOutlineDocument);
        }