hibernate mapping文件中 xmlns会导致linq to xml 查询不到对应的节点
2016-04-30 12:42
411 查看
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); } } }
相关文章推荐
- WKWebView与JS交互实战技巧之API介绍
- Objective-C 对象进阶:归档的概念和用法
- 最新版 android studio 配置 phonegap (windows环境)
- Swift 闭包(block)传值
- 常用的android 框架收藏
- 详解实现Android中实现View滑动的几种方式
- Android图片编译报错
- 【转】iOS容易造成循环引用的三种场景
- iOS程序猿之JSONKit的使用
- 浅谈Android支付宝快捷支付
- Android 中的 Service 全面总结
- Android 数据存储
- Objective-C之消息转发
- 微信本地开发测试环境
- Android 6.0的Launcher3的关于Hotseat的浅析
- IIS Express applicationhost.config 设置(一)
- button,android:onClick=""
- 对照Java学习Swift--方法(Methods)
- Android之Style简化代码
- iOS开发总结之 CATransition