码迷,mamicode.com
首页 > 移动开发 > 详细

hibernate mapping文件中 xmlns会导致linq to xml 查询不到对应的节点

时间:2016-04-30 14:11:01      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq;
using System.Xml.Linq;
using System.Xml;
using System.Windows.Forms;

namespace ConsoleApplication27
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            //<hibernate-mapping xmlns1="urn:nhibernate-mapping-2.2">
            //注意hibernate mapping文件中 xmlns会导致linq to xml 查询不到对应的节点,所以我吧xmlns改成xmlns1,事后自己再全文替换回来即可
            var path = AppDomain.CurrentDomain.BaseDirectory + "..\\..\\Mapping\\PosPositionProductMapping2.hbm.xml";

            var root = XElement.Load(path);

            var cps = root.Elements("class").Elements("property").ToList();
            bool find1 = false;
            bool find2 = false;
            cps.ForEach(c =>
            {
                string columnValue = c.Attribute("column").Value;
                if (columnValue.ToLower().Contains("CREATED_EMPLOYEE_NAME".ToLower()))
                {
                    
                    find1 = true;
                }
                if (c.Attribute("column").Value.ToLower().Contains("CREATED_EMPLOYEE_ID".ToLower()))
                {

                    find2 = true;
                }
            });
            XElement cls = root.Element("class");
            if (find1==false)
            {
              
              
                XElement xe = new XElement("property",
                    new XAttribute("name","CreatedEmployeeName"),
                    new XAttribute("column", "CREATED_EMPLOYEE_NAME"),
                    new XAttribute("update","false")

                    );

                cls.Add(xe);
               
            }
            if (find2==false)
            {


                XElement xe = new XElement("property",
                    new XAttribute("name", "CreatedEmployeeId"),
                    new XAttribute("column", "CREATED_EMPLOYEE_ID"),
                    new XAttribute("update", "false")

                    );

                cls.Add(xe);

            }
            root.Save(path);

        }
    }
}

 

hibernate mapping文件中 xmlns会导致linq to xml 查询不到对应的节点

标签:

原文地址:http://www.cnblogs.com/kexb/p/5448590.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!