当前位置: 首页>>代码示例>>C#>>正文


C# Linq.XDeclaration类代码示例

本文整理汇总了C#中System.Xml.Linq.XDeclaration的典型用法代码示例。如果您正苦于以下问题:C# XDeclaration类的具体用法?C# XDeclaration怎么用?C# XDeclaration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XDeclaration类属于System.Xml.Linq命名空间,在下文中一共展示了XDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: XDeclaration

 /// <summary>
 /// Initializes an instance of the <see cref="XDeclaration"/> class
 /// from another <see cref="XDeclaration"/> object.
 /// </summary>
 /// <param name="other">
 /// The <see cref="XDeclaration"/> used to initialize this <see cref="XDeclaration"/> object.
 /// </param>
 public XDeclaration(XDeclaration other)
 {
     if (other == null) throw new ArgumentNullException("other");
     _version = other._version;
     _encoding = other._encoding;
     _standalone = other._standalone;
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:14,代码来源:XDeclaration.cs

示例2: XmlHelper

 /// <summary>
 /// 创建一个新Xml文档,根据该文档创建一个XmlHelper对象
 /// </summary>
 /// <param name="version">文档描述的版本号</param>
 /// <param name="encoding">文档描述的编码</param>
 /// <param name="standalone">文档描述的standlone属性</param>
 /// <param name="rootName">根节点的名称</param>
 public XmlHelper(string version, string encoding, string standalone,string rootName)
 {
     this._doc = new XDocument();
     var declaration = new XDeclaration(version,encoding,standalone);
     this._doc.Declaration = declaration;
     this._doc.Add(new XElement(rootName)); 
 }
开发者ID:v5bep7,项目名称:Utility,代码行数:14,代码来源:XmlHelper.cs

示例3: XDeclaration

 public XDeclaration(XDeclaration other)
 {
     if (other == null)
         throw new ArgumentNullException ("other");
     this.version = other.version;
     this.encoding = other.encoding;
     this.standalone = other.standalone;
 }
开发者ID:nicocrm,项目名称:DotNetSDataClient,代码行数:8,代码来源:XDeclaration.cs

示例4: WriteToFile

        public void WriteToFile ()
        {
            // Corrected header of the plist
            string publicId = "-//Apple//DTD PLIST 1.0//EN";
            string stringId = "http://www.apple.com/DTDs/PropertyList-1.0.dtd";
            string internalSubset = null;
            XDeclaration declaration = new XDeclaration ("1.0", Encoding.UTF8.EncodingName, null);
            XDocumentType docType = new XDocumentType ("plist", publicId, stringId, internalSubset);

            this.XMLDict.Save (this.filePath, declaration, docType);
        }
开发者ID:laniley,项目名称:skillforge_unity,代码行数:11,代码来源:PListParser.cs

示例5: CreateDocumentWithContent

        public void CreateDocumentWithContent()
        {
            XDeclaration declaration = new XDeclaration("1.0", "utf-8", "yes");
            XComment comment = new XComment("This is a document");
            XProcessingInstruction instruction = new XProcessingInstruction("doc-target", "doc-data");
            XElement element = new XElement("RootElement");

            XDocument doc = new XDocument(declaration, comment, instruction, element);

            Assert.Equal(new XNode[] { comment, instruction, element }, doc.Nodes());
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:11,代码来源:SDMDocument.cs

示例6: GetXML

        public static string GetXML()
        {
            var employees = GetEmployees();
            var declaration = new XDeclaration("1.0", "utf-8", "yes");
            var doc = new XDocument(declaration, employees);

            var writer = new StringWriter();
            doc.Save(writer);

            return writer.GetStringBuilder().ToString();
        }
开发者ID:alphaCoder,项目名称:DotNetCode,代码行数:11,代码来源:GenerateXML.cs

示例7: WriteBookList

 public void WriteBookList(IEnumerable<Book> books)
 {
     XElement xBooks = new XElement("BookList",
         books.Select(book =>
         new XElement("Book",
             new XElement("Author", book.Author),
             new XElement("Title", book.Title),
             new XElement("Publisher", book.Publisher))));
     XDeclaration xDecl = new XDeclaration("1.0", "UTF-8", "no");
     XDocument xDoc = new XDocument(xDecl, xBooks);
     xDoc.Save(filePath);
 }
开发者ID:vitaliy-novik,项目名称:BSU.ASP.15.01.Day5.Novik,代码行数:12,代码来源:LinqToXMLSource.cs

示例8: CreateDocumentCopy

                /// <summary>
                /// Validate behavior of the XDocument copy/clone constructor.
                /// </summary>
                /// <returns>true if pass, false if fail</returns>
                //[Variation(Desc = "CreateDocumentCopy")]
                public void CreateDocumentCopy()
                {
                    try
                    {
                        new XDocument((XDocument)null);
                        Validate.ExpectedThrow(typeof(ArgumentNullException));
                    }
                    catch (Exception ex)
                    {
                        Validate.Catch(ex, typeof(ArgumentNullException));
                    }

                    XDeclaration declaration = new XDeclaration("1.0", "utf-8", "yes");
                    XComment comment = new XComment("This is a document");
                    XProcessingInstruction instruction = new XProcessingInstruction("doc-target", "doc-data");
                    XElement element = new XElement("RootElement");

                    XDocument doc = new XDocument(declaration, comment, instruction, element);

                    XDocument doc2 = new XDocument(doc);

                    IEnumerator e = doc2.Nodes().GetEnumerator();

                    // First node: declaration
                    Validate.IsEqual(doc.Declaration.ToString(), doc2.Declaration.ToString());

                    // Next node: comment
                    Validate.IsEqual(e.MoveNext(), true);
                    Validate.Type(e.Current, typeof(XComment));
                    Validate.IsNotReferenceEqual(e.Current, comment);
                    XComment comment2 = (XComment)e.Current;
                    Validate.IsEqual(comment2.Value, comment.Value);

                    // Next node: processing instruction
                    Validate.IsEqual(e.MoveNext(), true);
                    Validate.Type(e.Current, typeof(XProcessingInstruction));
                    Validate.IsNotReferenceEqual(e.Current, instruction);
                    XProcessingInstruction instruction2 = (XProcessingInstruction)e.Current;
                    Validate.String(instruction2.Target, instruction.Target);
                    Validate.String(instruction2.Data, instruction.Data);

                    // Next node: element.
                    Validate.IsEqual(e.MoveNext(), true);
                    Validate.Type(e.Current, typeof(XElement));
                    Validate.IsNotReferenceEqual(e.Current, element);
                    XElement element2 = (XElement)e.Current;
                    Validate.ElementName(element2, element.Name.ToString());
                    Validate.Count(element2.Nodes(), 0);

                    // Should be end.
                    Validate.IsEqual(e.MoveNext(), false);
                }
开发者ID:johnhhm,项目名称:corefx,代码行数:57,代码来源:SDMDocument.cs

示例9: CompileDocument

        public XDocument CompileDocument(ConnectionInfo serializationTarget, bool fullFileEncryption, bool export)
        {
            var rootNodeInfo = GetRootNodeFromConnectionInfo(serializationTarget);
            _encryptionKey = rootNodeInfo.PasswordString.ConvertToSecureString();
            var rootElement = CompileRootNode(rootNodeInfo, fullFileEncryption, export);

            CompileRecursive(serializationTarget, rootElement);
            var xmlDeclaration = new XDeclaration("1.0", "utf-8", null);
            var xmlDocument = new XDocument(xmlDeclaration, rootElement);
            if (fullFileEncryption)
                xmlDocument = new XmlConnectionsDocumentEncryptor(_cryptographyProvider).EncryptDocument(xmlDocument, _encryptionKey);
            return xmlDocument;
        }
开发者ID:mRemoteNG,项目名称:mRemoteNG,代码行数:13,代码来源:XmlConnectionsDocumentCompiler.cs

示例10: CortanaXmlGenerator

 public CortanaXmlGenerator(string prefix,string example)
 {
     doc = new XDocument();
     XDeclaration dec = new XDeclaration("1.0", "utf-8", "no");
     doc.Declaration = dec;
     XElement root = new XElement("VoiceCommands");
     root.SetAttributeValue("def", "defVal");
     doc.Add(root);
     commandSet = new XElement("CommandSet");
     commandSet.SetAttributeValue("xmllang", "ja-JP");
     commandSet.Add(new XElement("CommandPrefix", prefix));
     commandSet.Add(new XElement("Example", example));
     root.Add(commandSet);
 }
开发者ID:garicchi,项目名称:CortanaCommand,代码行数:14,代码来源:CortanaXmlGenerator.cs

示例11: InitDebils

 public static void InitDebils()
 {
     XDocument Debili = new XDocument();
       XDeclaration Xdec = new XDeclaration("1.0", "utf-8", "yes");
       XComment Com = new XComment("Не изменяйте нижнюю строчку");
       XElement Stud =  new XElement("StudList",
       new XElement("Class", new XAttribute("ID", 1),
     new XElement("Name", "Витек Мартынов"),
     new XElement("Name", "Батруха Иисусов"),
     new XElement("Name", "Шланг Волосатый")));
       //Debili.Add(Xdec);
       Debili.Add(Stud);
       Debili.Save("Test.xml");
 }
开发者ID:Mexahoid,项目名称:CSF,代码行数:14,代码来源:Heart.cs

示例12: EqualDeclarations

        private static bool EqualDeclarations(XDeclaration expected, XDeclaration actual)
        {
            if (expected == null && actual == null)
            {
                return true;
            }

            if (expected == null || actual == null)
            {
                return false;
            }

            // Note that this ignores 'Standalone' property comparison.
            return string.Equals(expected.Version, actual.Version, StringComparison.OrdinalIgnoreCase)
                && string.Equals(expected.Encoding, actual.Encoding, StringComparison.OrdinalIgnoreCase);
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:16,代码来源:XmlAssert.cs

示例13: CreateDocumentCopy

        public void CreateDocumentCopy()
        {
            Assert.Throws<ArgumentNullException>(() => new XDocument((XDocument)null));

            XDeclaration declaration = new XDeclaration("1.0", "utf-8", "yes");
            XComment comment = new XComment("This is a document");
            XProcessingInstruction instruction = new XProcessingInstruction("doc-target", "doc-data");
            XElement element = new XElement("RootElement");

            XDocument doc = new XDocument(declaration, comment, instruction, element);

            XDocument doc2 = new XDocument(doc);

            IEnumerator e = doc2.Nodes().GetEnumerator();

            // First node: declaration
            Assert.Equal(doc.Declaration.ToString(), doc2.Declaration.ToString());

            // Next node: comment
            Assert.True(e.MoveNext());
            Assert.IsType<XComment>(e.Current);
            Assert.NotSame(comment, e.Current);

            XComment comment2 = (XComment)e.Current;
            Assert.Equal(comment.Value, comment2.Value);

            // Next node: processing instruction
            Assert.True(e.MoveNext());
            Assert.IsType<XProcessingInstruction>(e.Current);
            Assert.NotSame(instruction, e.Current);

            XProcessingInstruction instruction2 = (XProcessingInstruction)e.Current;
            Assert.Equal(instruction.Target, instruction2.Target);
            Assert.Equal(instruction.Data, instruction2.Data);

            // Next node: element.
            Assert.True(e.MoveNext());
            Assert.IsType<XElement>(e.Current);
            Assert.NotSame(element, e.Current);

            XElement element2 = (XElement)e.Current;
            Assert.Equal(element.Name.ToString(), element2.Name.ToString());
            Assert.Empty(element2.Nodes());

            // Should be end.
            Assert.False(e.MoveNext());
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:47,代码来源:SDMDocument.cs

示例14: Starship

        /// <summary>
        /// create a new ship's data file
        /// </summary>
        /// <param name="shipname"></param>
        /// <param name="man"></param>
        /// <param name="power"></param>
        /// <param name="jump"></param>
        /// <param name="power"></param>
        /// <param name="cargo">int - cargo capacity in Dtons</param>
        /// <param name="credits">int - current credits</param>
        /// <param name="day">int - day (0..365)</param>
        /// <param name="jumpcost">int - cost per jump (fuel, life support, etc)</param>
        /// <param name="monthly">int - monthly costs (mortgage, maintenance, etc)</param>
        /// <param name="sec">string - SEC string of initial system</param>
        /// <param name="version">string - version: CT, MT, T5, CU</param>
        /// <param name="year">int - imperial year (i.e., 1105)</param>
        /// <param name="secfile">string - SEC format file</param>
        public Starship(string shipname, int man, int power, int jump, int cargo, int monthly, int jumpcost, int day, int year, 
            int credits, string version, string secfile, string sec, string sectorname, int tradeDM, bool illegals)
        {
            XDocument ns = new XDocument();
            XDeclaration dec = new XDeclaration("1.0", "utf-8", "yes");
            ns.AddAnnotation(dec);

            XElement rootNode = new XElement("ShipData");
            ns.Add(rootNode);

            ns.Element("ShipData").Add(
                new XElement("system",
                    new XAttribute("version", version),
                    new XElement("day", day.ToString()),
                    new XElement("year", year.ToString()),
                    new XElement("sec", sec),
                    new XElement("secfile", secfile),
                    new XElement("sectorName", sectorname),
                    new XElement("cargoID",0),
                    new XElement("tradeDM", tradeDM),
                    new XElement("illegals", illegals)));

            ns.Element("ShipData").Add(
                new XElement("Ship"));

            ns.Element("ShipData").Element("Ship").Add(
                    new XElement("Name", shipname),
                    new XElement("Manuever", man.ToString()),
                    new XElement("Power", power.ToString()),
                    new XElement("Jump", jump.ToString()),
                    new XElement("Cargo", cargo.ToString()),
                    new XElement("CargoHeld", "0"),
                    new XElement("credits", credits),
                    new XElement("costs",
                        new XElement("Monthly", monthly.ToString()),
                        new XElement("perJump", jumpcost.ToString()),
                        new XElement("lastPaid", String.Format("{0:000}-{1:0000}", day, year))));

            ns.Element("ShipData").Add(
                new XElement("Cargo"));
            ns.Element("ShipData").Add(
                new XElement("Travelogue"));

            ns.Save(shipname + ".xml");

            clearData();
        }
开发者ID:COliver988,项目名称:Traveller,代码行数:64,代码来源:TravellerClass.cs

示例15: TestDefaultXmlFormatter

		public void TestDefaultXmlFormatter()
		{
			var sut = _xmlFormatter;

			XDeclaration declaration = new XDeclaration("1.0", "UTF-8", null);
			XElement content = new XElement("root", new XElement("person", 1));
			XDocument document = new XDocument(declaration, content);

			string xmlString = sut.Format(document);

			string expected =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<root>
  <person>1</person>
</root>";
			Assert.Equal(expected, xmlString);
		}
开发者ID:dance2die,项目名称:MyAnimeListSharp,代码行数:17,代码来源:XmlFormatterTest.cs


注:本文中的System.Xml.Linq.XDeclaration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。