您的位置:首页 > 其它

XmlDeclaration.Standalone 属性

2007-07-18 14:32 369 查看
在SharpDevelop中发现的Standalone属性,这是msdn上的解释

获取或设置独立属性的值。

如果 XML 文档所需要的所有实体声明都包含在文档内,则有效值为 yes,或者如果需要外部文档类型定义 (DTD),则为 no。
如果 XML 声明中没有独立属性 (Attribute),该属性 (Property) 将返回 String.Empty。

下面的示例创建一个 XmlDeclaration 节点,并将其添加到 XML 文档中。


using System;


using System.IO;


using System.Xml;




public class Sample




...{




public static void Main()




...{




// Create and load the XML document.


XmlDocument doc = new XmlDocument();


string xmlString = "<book><title>Oberon's Legacy</title></book>";


doc.Load(new StringReader(xmlString));




// Create an XML declaration.


XmlDeclaration xmldecl;


xmldecl = doc.CreateXmlDeclaration("1.0",null,null);


xmldecl.Encoding="UTF-8";


xmldecl.Standalone="yes";




// Add the new node to the document.


XmlElement root = doc.DocumentElement;


doc.InsertBefore(xmldecl, root);




// Display the modified XML document


Console.WriteLine(doc.OuterXml);




System.Console.Read();




}


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: