设为首页 加入收藏

TOP

以对象的方式来访问xml数据表(二)(二)
2019-09-03 03:27:41 】 浏览:113
Tags:对象 方式 访问 xml 数据
else { Notes.Elements().Last().LastNode.AddAfterSelf(new XElement(xmlProperties[i], propertyValues[i])); } } } else { Notes.AddFirst(new XElement(noteName, new XAttribute("No", 1))); for (int i = 0; i < xmlProperties.Length; i++) { if (i == 0) { Notes.Element(noteName).AddFirst(new XElement(xmlProperties[i], propertyValues[i])); } else { Notes.Element(noteName).LastNode.AddAfterSelf(new XElement(xmlProperties[i], propertyValues[i])); } } } return true; } else { return false; } } catch (Exception e) { throw e; //return false; } } //添加记录:添加到末尾(方法二) public bool AddNote(XElement newNote) { try { if (newNote.Elements().Count() == xmlProperties.Length) { if (Notes.Elements(noteName).Count() > 0) { int newNo; var lastNote = from Note in Notes.Elements() select Convert.ToInt32(Note.Attribute("No").Value); newNo = lastNote.Max() + 1; if(newNote.Attribute("No") == null) { newNote.Add(new XAttribute("No", newNo)); } else { newNote.Attribute("No").Value = newNo.ToString(); } Notes.Elements().Last().AddAfterSelf(newNote); } else { if (newNote.Attribute("No") == null) { newNote.Add(new XAttribute("No", 1)); } else { newNote.Attribute("No").Value = "1"; } Notes.AddFirst(newNote); } return true; } else { return false; } } catch (Exception e) { throw e; //return false; } } //添加记录:添加到开头 public bool AddFistNote(XElement newNote) { try { if (newNote.Elements().Count() == xmlProperties.Length) { if (Notes.Elements(noteName).Count() > 0) { int newNo; var lastNote = from Note in Notes.Elements() select Convert.ToInt32(Note.Attribute("No").Value); newNo = lastNote.Max() + 1; if (newNote.Attribute("No") == null) { newNote.Add(new XAttribute("No", newNo)); } else { newNote.Attribute("No").Value = newNo.ToString(); } Notes.AddFirst(newNote); } else { if (newNote.Attribute("No") == null) { newNote.Add(new XAttribute("No", 1)); } else { newNote.Attribute("No").Value = "1"; } Notes.AddFirst(newNote); } return true; } else { return false; } } catch (Exception e) { throw e; //return false; } } //删除记录(单一索引) public bool DeletNote(string no = "", params string[] propertyValues) { try { bool okFlag = false; if (propertyValues.Length > xmlProperties.Length) { return false; } else { if (no == "") //按属性值相等删除 { for (int i = 0; i < propertyValues.Length; i++) { if (propertyValues[i] == "") continue; if (Notes.Elements(noteName).Count() == 0) return false;//数据文件内容为空 var proNotes = Notes.Elements(noteName).Elements(xmlProperties[i]).Where(m => m.Value == propertyValues[i]); foreach (var item in proNotes) { item.Parent.Remove(); okFlag = true; } } } else //按编号相等删除 { if (Notes.Elements(noteName).Count() == 0) return false;//数据文件内容为空 var proNote = Notes.Elements(noteName).SingleOrDefault(m => m.Attribute("No").Value == no); if (proNote != null) { proNote.Remove(); okFl
首页 上一页 1 2 3 4 下一页 尾页 2/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇在Visual Studio 2019中开启预览.. 下一篇运算符

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目