91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 0.14M
    文件類型: .rar
    金幣: 1
    下載: 0 次
    發布日期: 2024-05-01
  • 語言: C#
  • 標簽: Xml??解析??文件??實例??

資源簡介

XML文件解析方法

資源截圖

代碼片段和文件信息

using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?System.xml;
using?System.xml.Linq;

namespace?_01xml讀寫操作
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}

????????//讀取xml文件
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????#region?將xml文件遞歸加載到TreeView上

????????????//=============通過XDocument將xml文件遞歸加載到TreeView上==============
????????????////1.讀取xml文件(XDocument)
????????????////1.加載xml文件
????????????//XDocument?document?=?XDocument.Load(“rss_sportslq.xml“);
????????????////2先獲取根節點
????????????//XElement?rootElement?=?document.Root;

????????????////3.將xml的根元素加載到TreeView的根節點上
????????????//TreeNode?rootNode?=?treeView1.Nodes.Add(rootElement.Name.ToString());

????????????////4.遞歸加載
????????????//LoadxmlToTreeView(rootElement?rootNode.Nodes);

????????????#endregion



????????????#region?通過xmlDocument將xml遞歸加載到TreeView上

????????????//1.加載xml文件到對象
????????????xmlDocument?document?=?new?xmlDocument();
????????????//將xml文件加載到dom對象上
????????????document.Load(“rss_sportslq.xml“);
????????????//獲得xml的根節點(根元素)
????????????xmlElement?rootElement?=?document.DocumentElement;
????????????//先把xml的根元素加載到TreeView上
????????????TreeNode?rootNode?=?treeView1.Nodes.Add(rootElement.Name);

????????????//實現遞歸將xml加載到TreeView中
????????????LoadToTreeByxmlDocument(rootElement?rootNode.Nodes);


????????????#endregion
????????}

????????private?void?LoadToTreeByxmlDocument(xmlElement?rootElement?TreeNodeCollection?treeNodeCollection)
????????{
????????????//循環rootElement下的所有子元素加載到treeNodeCollection集合中
????????????foreach?(xmlNode?item?in?rootElement.ChildNodes)
????????????{
????????????????//在繼續之前需要判斷一下當前節點是什么類型的節點
????????????????if?(item.NodeType?==?xmlNodeType.Element)
????????????????{
????????????????????//如果當前節點是一個“元素”節點,則把當前節點加載到TreeView上
????????????????????TreeNode?node?=?treeNodeCollection.Add(item.Name);
????????????????????//遞歸調用
????????????????????LoadToTreeByxmlDocument((xmlElement)item?node.Nodes);
????????????????}
????????????????else?if?(item.NodeType?==?xmlNodeType.Text?|?item.NodeType?==?xmlNodeType.CDATA)
????????????????{
????????????????????treeNodeCollection.Add(item.InnerText);
????????????????}
????????????}

????????}

????????//通過XDocument的方式將xml元素遞歸加載到TreeView上。
????????private?void?LoadxmlToTreeView(XElement?rootElement?TreeNodeCollection?treeNodeCollection)
????????{
????????????//獲取根元素rootElement下的所有的子元素
????????????//rootElement.Elements();
????????????//遍歷rootElement下的所有的子元素(直接子元素)
????????????foreach?(XElement?item?in?rootElement.Elements())
????????????{
????????????????if?(item.Elements().Count()?==?0)
????????????????{
????????????????????treeNodeCollection.Add(item.Name.ToString()).Nodes.Add

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????2288??2013-06-16?16:55??Sln20130616.sln

?????文件???????3867??2013-06-16?15:58??01xml讀寫操作\01xml讀寫操作.csproj

?????文件????????227??2013-06-16?10:11??01xml讀寫操作\01xml讀寫操作.csproj.user

?????文件??????11776??2013-06-16?16:11??01xml讀寫操作\bin\Debug\01xml讀寫操作.exe

?????文件??????28160??2013-06-16?16:11??01xml讀寫操作\bin\Debug\01xml讀寫操作.pdb

?????文件??????11600??2013-06-16?16:04??01xml讀寫操作\bin\Debug\01xml讀寫操作.vshost.exe

?????文件????????490??2010-03-17?22:39??01xml讀寫操作\bin\Debug\01xml讀寫操作.vshost.exe.manifest

?????文件????????501??2013-06-16?10:47??01xml讀寫操作\bin\Debug\List.xml

?????文件????????517??2013-06-16?10:58??01xml讀寫操作\bin\Debug\ListNew.xml

?????文件??????11129??2013-06-16?15:19??01xml讀寫操作\bin\Debug\rss_sportslq.xml

?????文件????????201??2013-06-16?10:33??01xml讀寫操作\bin\Debug\school.xml

?????文件????????275??2013-06-16?10:11??01xml讀寫操作\bin\Debug\students.xml

?????文件??????12757??2013-06-16?15:30??01xml讀寫操作\Form1.cs

?????文件???????3786??2013-06-16?15:11??01xml讀寫操作\Form1.Designer.cs

?????文件???????5817??2013-06-16?15:11??01xml讀寫操作\Form1.resx

?????文件???????1052??2013-06-16?16:11??01xml讀寫操作\obj\x86\Debug\01xml讀寫操作.csproj.FileListAbsolute.txt

?????文件????????975??2013-06-16?15:14??01xml讀寫操作\obj\x86\Debug\01xml讀寫操作.csproj.GenerateResource.Cache

?????文件???????9040??2013-06-16?16:11??01xml讀寫操作\obj\x86\Debug\01xml讀寫操作.csprojResolveAssemblyReference.cache

?????文件??????11776??2013-06-16?16:11??01xml讀寫操作\obj\x86\Debug\01xml讀寫操作.exe

?????文件??????28160??2013-06-16?16:11??01xml讀寫操作\obj\x86\Debug\01xml讀寫操作.pdb

?????文件???????2855??2013-06-16?10:04??01xml讀寫操作\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

?????文件???????6684??2013-06-16?16:11??01xml讀寫操作\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

?????文件????????180??2013-06-16?16:11??01xml讀寫操作\obj\x86\Debug\_01xml讀寫操作.Form1.resources

?????文件????????180??2013-06-16?16:11??01xml讀寫操作\obj\x86\Debug\_01xml讀寫操作.Properties.Resources.resources

?????文件????????295??2013-06-16?15:32??01xml讀寫操作\Orders.xml

?????文件????????499??2013-06-16?10:04??01xml讀寫操作\Program.cs

?????文件???????1366??2013-06-16?10:04??01xml讀寫操作\Properties\AssemblyInfo.cs

?????文件???????2888??2013-06-16?10:04??01xml讀寫操作\Properties\Resources.Designer.cs

?????文件???????5612??2013-06-16?10:04??01xml讀寫操作\Properties\Resources.resx

?????文件???????1105??2013-06-16?10:04??01xml讀寫操作\Properties\Settings.Designer.cs

............此處省略96個文件信息

評論

共有 條評論