XML 读
StringBuilder output = new
StringBuilder();
String xmlString =
@"<bookstore>
<book genre='novel' ISBN='10-861003-324'>
<title>The Handmaid's Tale</title>
<price>19.95</price>
</book>
<book genre='novel' ISBN='1-861001-57-5'>
<title>Pride And Prejudice</title>
<price>24.95</price>
</book>
</bookstore>";
// Load the file and ignore all white space.
XmlReaderSettings settings = new
XmlReaderSettings();
settings.IgnoreWhitespace = true
;
using
(XmlReader reader = XmlReader.Create(new
StringReader(xmlString), settings))
{
// Move the reader to the second book node.
reader.MoveToContent();
reader.ReadToDescendant("book"
);
reader.Skip();
//Skip the first book.
// Parse the file starting with the second book node.
do
{
switch
(reader.NodeType)
{
case
XmlNodeType.Element:
output.AppendLine("<"
+ reader.Name);
while
(reader.MoveToNextAttribute())
{
output.AppendLine(" "
+ reader.Name + "="
+ reader.Value);
}
output.AppendLine(">"
);
break
;
case
XmlNodeType.Text:
output.AppendLine(reader.Value);
break
;
case
XmlNodeType.EndElement:
output.AppendLine("</"
+ reader.Name + ">"
);
break
;
}
}
while
(reader.Read());
}
OutputTextBlock.Text = output.ToString();
XML是目前最常用的通用数据传输与处理接口类型。本文介绍如何用C#.NET读写XML文档资料。
<?xml version="1.0" encoding="utf-8"?>
相关文档:
XML Schema import 元素
定义和用法
import 元素用于向一个文档添加带有不同目标命名空间的多个 schema。
元素信息
出现次数
无限制
父元素
schema
内容
annotation
语法
<import
id=ID
namespace=anyURI
schemaLocation=anyURI
any attributes
>
(annotation?)
< ......
1)Xml文档示例(xmlsample.xml):
Code
<?xml version="1.0" encoding="iso-8859-1" ?>
<music>
<song title="Oh,girl">
<artist>The Chi-lites</artist>
<genre>Soul</genre>
&nb ......
/// <summary>
/// 支持XML序列化的泛型 Dictionary
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TValue"></typeparam>
[XmlRoot("SerializableDictionary")]
public class SerializableDictionary<TKey, TValue& ......
var createXML = function (str) {
if (typeof DOMParser !== "undefined") {
return (new DOMParser()).parsefromString(str, "application/xml");
}else if (typeof ActiveXObject != "undefined") {
if (typeof arguments.callee.activeXString !== "string" ......
DECLARE @XMLdoc XML
SET @XMLdoc =
'<Book name="SQL Server 2000 Fast Answers">
<Chapters>
<Chapter id="1" name="Installation, Upgrades">
<CreateDate>2009-12-30</CreateDate>
</Chapter>
<Chapter id="2" name="Configuring SQL Server"/>
<Chapter i ......