惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
The GitHub Blog
The GitHub Blog
C
Check Point Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
F
Full Disclosure
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
G
GRAHAM CLULEY
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
V
Vulnerabilities – Threatpost
K
Kaspersky official blog
博客园 - 司徒正美
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
Project Zero
Project Zero
云风的 BLOG
云风的 BLOG
Cisco Talos Blog
Cisco Talos Blog
Know Your Adversary
Know Your Adversary
雷峰网
雷峰网
V
V2EX - 技术
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Spread Privacy
Spread Privacy
罗磊的独立博客
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
SecWiki News
SecWiki News
Schneier on Security
Schneier on Security
O
OpenAI News
Jina AI
Jina AI
PCI Perspectives
PCI Perspectives
Cyberwarzone
Cyberwarzone
Y
Y Combinator Blog
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog RSS Feed
I
InfoQ
D
Docker
P
Palo Alto Networks Blog
Recorded Future
Recorded Future
M
MIT News - Artificial intelligence
博客园 - Franky
B
Blog
Scott Helme
Scott Helme
博客园 - 叶小钗
D
DataBreaches.Net

博客园 - 雨衣blog

windows 7 下安装 IIS 和 ArcGis Server 9.3 遇到的问题及解决方法 win7 64位系统使用VS2010生成时出现中文目录乱码问题的解决方法【转】 const和static readonly区别 笔记本商家 辅食 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 如何修改 VS2010 的 HelpLibrary(即MSDN)的安装路径 DevExpress控件使用 - 雨衣blog - 博客园 Java设计模式之综述篇 通过拦截器来统计每个action的执行时间 二分法快速查找的递归算法 C#编码好习惯 C#四种排序算法 认识oracle数据类型 在sqlplus中查看 open_cursors的数值: c#获取本机IP,机器名,然后是操作系统版本 - 雨衣blog - 博客园
xml操作类 - 雨衣blog - 博客园
雨衣blog · 2008-10-26 · via 博客园 - 雨衣blog

public class ManagementXml
...{
public ManagementXml()
...{
}
/**////


/// 添加元素
///

public void AddElement()
...{
System.Xml.XmlNode newElement;
newElement = xml.CreateElement("Keyword");
newElement.InnerText = "Value";
xml.AppendChild(newElement);
}
/**////


/// 列举所有属性
///

public void EnumAttribute()
...{
foreach (System.Xml.XmlAttribute attribute in node.Attributes)
...{

}
}
/**////


/// 查到节点名
///

public void Find_A_Node()
...{
System.Xml.XmlNodeList nodes;
nodes = xml.GetElementsByTagName("ElementName");
}
/**////


/// 从Xml文件中提出模式
///

public void Infer_A_Schema_From_A_Xml()
...{
// Gets the schema.
System.Xml.Schema.XmlSchemaInference infer = new System.Xml.Schema.XmlSchemaInference();
System.Xml.Schema.XmlSchemaSet sc = new System.Xml.Schema.XmlSchemaSet();
sc = infer.InferSchema(new System.Xml.XmlTextReader("sample.xml"));
// Writes the schema.
System.Xml.XmlWriter w = System.Xml.XmlWriter.Create(new System.IO.StreamWriter("sampleSchema.xsd"));

foreach (System.Xml.Schema.XmlSchema schema in sc.Schemas())
...{
schema.Write(w);
}

// Update the schema with another xml fragment.
sc = infer.InferSchema(System.Xml.XmlReader.Create("anothersample.xml"), sc);
w = System.Xml.XmlWriter.Create(new System.IO.StreamWriter("anotherschema.xsd"));
foreach (System.Xml.Schema.XmlSchema schema in sc.Schemas())
...{
schema.Write(w);
}

}
/**////


/// 重新声明已命名节点
///

public void Iterate_Named_Nodes()
...{
foreach (System.Xml.XmlNode node in xmlDoc.GetElementsByTagName("ElementName"))
...{

}
}
/**////


/// 用XPathNavigator导航数据
///

public void NavigateData_with_XPathNavigator()
...{
System.Xml.XPath.XPathNavigator nav = xmlDoc.CreateNavigator();

// Move to the first non-comment element.
nav.MoveToChild(System.Xml.XPath.XPathNodeType.Element);

System.Xml.XPath.XPathNodeIterator nodeIterator = nav.SelectChildren(System.Xml.XPath.XPathNodeType.Element);

while (nodeIterator.MoveNext())
...{

}
}
/**////


/// 从Xml中读取数据到类
///

public void Read_ClassData_From_Xml()
...{
System.Xml.XmlSerializer reader = new System.Xml.XmlSerializer(typeof(TheClass));
using (System.IO.StreamReader file = new System.IO.StreamReader(@"ClassData.xml"))
...{
TheClass fileData;

fileData = (TheClass)reader.Deserialize(file);
}
}
/**////


/// 用XmlTextReader读取数据
///

public void Read_Data_With_XmlTextReader()
...{
System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader("Snippet.xml");

string contents = reader.ReadInnerXml();
}
/**////


/// 从字符串读取Xml
///

public void Read_Xml_Form_String()
...{
// Create the reader.
System.Xml.XmlReader reader = System.Xml.XmlReader.Create(new System.IO.StringReader("

"));

while (reader.Read())
...{

}
}
/**////


/// 从Url读取Xml
///

public void ReadXmlFromUrl()
...{
string myUrl = "http://www.contoso.com/books.xml";
System.Xml.XmlReader reader = System.Xml.XmlReader.Create(myUrl);

while (reader.Read())
...{

}
}
/**////


/// 用XPathNavigator读取节点数据,相当与sql查询,当然可以进行更新,查询,删除,添加了
///

public void Selet_Nodes_With_XPathNavigator()
...{
System.Xml.XPath.XPathExpression myXPathExpr;
System.Xml.XPath.XPathDocument myXPathDocument = new System.Xml.XPath.XPathDocument(@"data.xml");
// Create an XPathNavigator.
System.Xml.XPath.XPathNavigator myXPathNavigator = myXPathDocument.CreateNavigator();
// Get the Book elements.
string selectExpr = "parent/child";
// Ensure we are at the root node.
myXPathNavigator.MoveToRoot();
myXPathExpr = myXPathNavigator.Compile(selectExpr);
// Create an XPathNodeIterator to walk over the selected nodes.
System.Xml.XPath.XPathNodeIterator myXPathNodeIterator = myXPathNavigator.Select(myXPathExpr);
}
/**////
/// 用XSl sheet将XMl转化为Html
///

public void Transform_Xml_To_Html_Using_Xsl()
...{
using (System.IO.FileStream stream = System.IO.File.Open("output.html", System.IO.FileMode.Create))
...{
// Create XsltCommand compile stylesheet.
System.Xml.Xsl.XslCompiledTransform processor = new System.Xml.Xsl.XslCompiledTransform();
processor.Load("stylesheet.xsl");

// Transform the file.
processor.Transform("data.xml", null, stream);
}
}
/**////


/// 用XSlT将XMl转化为Html
///

public void Transform_Xml_To_Html_Using_Xslt()
...{
System.Xml.Xsl.XslCompiledTransform xslt = new System.Xml.Xsl.XslCompiledTransform();

xslt.Load("theXsltFile.xslt");
xslt.Transform("theXmlFile.xml", "theOutputFile.html");
}
/**////


/// 将类的数据写入Xml
///

public void WriteClassDataToXml()
...{
System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(typeof(System.Collections.ArrayList));

using (System.IO.StreamWriter file = new System.IO.StreamWriter("SerializedData.xml"))
...{
writer.Serialize(file, dataToWrite);
}
}

}