本文整理汇总了C#中System.Xml.XmlSignificantWhitespace.NodeType属性的典型用法代码示例。如果您正苦于以下问题:C# XmlSignificantWhitespace.NodeType属性的具体用法?C# XmlSignificantWhitespace.NodeType怎么用?C# XmlSignificantWhitespace.NodeType使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。
在下文中一共展示了XmlSignificantWhitespace.NodeType属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.IO;
using System.Xml;
public class Sample {
private XmlNode currNode;
private const String filename="space.xml";
XmlTextReader reader=null;
public static void Main() {
Sample test = new Sample();
}
public Sample() {
XmlDocument doc = new XmlDocument();
doc.LoadXml("<!-- Sample XML fragment -->" +
"<author xml:space='preserve'>" +
"<first-name>Eva</first-name>"+
"<last-name>Corets</last-name>" +
"</author>");
Console.WriteLine("InnerText before...");
Console.WriteLine(doc.DocumentElement.InnerText);
// Add white space.
currNode=doc.DocumentElement;
XmlSignificantWhitespace sigws=doc.CreateSignificantWhitespace("\t");
currNode.InsertAfter(sigws, currNode.FirstChild);
Console.WriteLine();
Console.WriteLine("InnerText after...");
Console.WriteLine(doc.DocumentElement.InnerText);
// Save and then display the file.
doc.Save(filename);
Console.WriteLine();
Console.WriteLine("Reading file...");
ReadFile(filename);
}
// Parse the file and print out each node.
public void ReadFile(String filename) {
try {
reader = new XmlTextReader(filename);
String sNodeType = null;
while (reader.Read()) {
sNodeType = NodeTypeToString(reader.NodeType);
// Print the node type, name, and value.
Console.WriteLine("{0}<{1}> {2}", sNodeType, reader.Name, reader.Value);
}
}
finally {
if (reader != null)
reader.Close();
}
}
public static String NodeTypeToString(XmlNodeType nodetype) {
String sNodeType = null;
switch (nodetype) {
case XmlNodeType.None:
sNodeType = "None";
break;
case XmlNodeType.Element:
sNodeType = "Element";
break;
case XmlNodeType.Attribute:
sNodeType = "Attribute";
break;
case XmlNodeType.Text:
sNodeType = "Text";
break;
case XmlNodeType.Comment:
sNodeType = "Comment";
break;
case XmlNodeType.Document:
sNodeType = "Document";
break;
case XmlNodeType.Whitespace:
sNodeType = "Whitespace";
break;
case XmlNodeType.SignificantWhitespace:
sNodeType = "SignificantWhitespace";
break;
case XmlNodeType.EndElement:
sNodeType = "EndElement";
break;
}
return sNodeType;
}
}
开发者ID:.NET开发者,项目名称:System.Xml,代码行数:95,代码来源:XmlSignificantWhitespace.NodeType
注:本文中的System.Xml.XmlSignificantWhitespace.NodeType属性示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论