コード例 #1
0
ファイル: Echange.cs プロジェクト: yoan-durand/TP
        public List<DBO.Books> parseDom(string filename)
        {
            string balise = "/Books/book[";
            DBO.Books b = new DBO.Books ();
            List<DBO.Books> list = new List<DBO.Books>();
            XmlDocument xml = new XmlDocument ();
            int i = 1;
            xml.Load(XmlReader.Create("file:///"+System.Web.HttpContext.Current.Server.MapPath("~/")+"/" +filename));
            b.IdLib = xml.SelectSingleNode("/Books/@IDLibrary").InnerText;
            string xpath = balise + i.ToString() + "]";
            XmlNode node = xml.SelectSingleNode(xpath);

            list.Add(b);
            if (node != null)
            {
                while ((node != null) && (node.HasChildNodes))
                {
                    list.Add(new DBO.Books(xml.SelectSingleNode(xpath + "/@name").InnerText, xml.SelectSingleNode(xpath + "/isbn").InnerText, xml.SelectSingleNode(xpath + "/author").InnerText,
                        xml.SelectSingleNode(xpath + "/number").InnerText, xml.SelectSingleNode(xpath + "/DateBack").InnerText));
                    i++;
                    xpath = balise + i.ToString() + "]";
                    node = xml.SelectSingleNode(xpath);
                }
            }

            return (list);
        }
コード例 #2
0
ファイル: Echange.cs プロジェクト: yoan-durand/TP
        public List<DBO.Books> parse_linq(string filename)
        {
            List<DBO.Books> list = new List<DBO.Books>();
            XDocument xdoc = XDocument.Load(XmlReader.Create("file:///"+System.Web.HttpContext.Current.Server.MapPath("~/")+"/" +filename));
            var id = from lib in xdoc.Descendants("Books")
                     where (string)lib.Attribute("IDLibrary") != ""
                     select lib;

            var b = from book in xdoc.Descendants("book")
                    select book;

            DBO.Books first = new DBO.Books();
            foreach (XElement l_id in id)
            {
                first.IdLib = (string) l_id.Attribute("IDLibrary");
            }
            list.Add(first);

            foreach (XElement books in b)
            {
                string name = (string)books.Attribute("name");
                string isbn = books.Element("isbn").Value;
                string author = books.Element("author").Value;
                string number = books.Element("number").Value;
                string date = books.Element("DateBack").Value;
                list.Add(new DBO.Books(name, isbn, author, number, date));
                Console.WriteLine(books);
            }

            return list;
        }