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


C# XmlDocument.CreateDocumentType方法代码示例

本文整理汇总了C#中XmlDocument.CreateDocumentType方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.CreateDocumentType方法的具体用法?C# XmlDocument.CreateDocumentType怎么用?C# XmlDocument.CreateDocumentType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XmlDocument的用法示例。


在下文中一共展示了XmlDocument.CreateDocumentType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SavePlistToFile

 public static bool SavePlistToFile(String xmlFile, Hashtable plist)
 {
     // If the hashtable is null, then there's apparently an issue; fail out.
     if (plist == null) {
         Debug.LogError("Passed a null plist hashtable to SavePlistToFile.");
         return false;
     }
     // Create the base xml document that we will use to write the data
     XmlDocument xml = new XmlDocument();
     xml.XmlResolver = null; //Disable schema/DTD validation, it's not implemented for Unity.
     // Create the root XML declaration
     // This, and the DOCTYPE, below, are standard parts of a XML property list file
     XmlDeclaration xmldecl = xml.CreateXmlDeclaration("1.0", "UTF-8", null);
     xml.PrependChild(xmldecl);
     // Create the DOCTYPE
     XmlDocumentType doctype = xml.CreateDocumentType("plist", "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null);
     xml.AppendChild(doctype);
     // Create the root plist node, with a version number attribute.
     // Every plist file has this as the root element.  We're using version 1.0 of the plist scheme
     XmlNode plistNode = xml.CreateNode(XmlNodeType.Element, "plist", null);
     XmlAttribute plistVers = (XmlAttribute)xml.CreateNode(XmlNodeType.Attribute, "version", null);
     plistVers.Value = "1.0";
     plistNode.Attributes.Append(plistVers);
     xml.AppendChild(plistNode);
     // Now that we've created the base for the XML file, we can add all of our information to it.
     // Pass the plist data and the root dict node to SaveDictToPlistNode, which will write the plist data to the dict node.
     // This function will itterate through the hashtable hierarchy and call itself recursively for child hashtables.
     if (!SaveDictToPlistNode(plistNode, plist)) {
         // If for some reason we failed, post an error and return false.
         Debug.LogError("Failed to save plist data to root dict node: " + plist);
         return false;
     } else { // We were successful
         // Create a StreamWriter and write the XML file to disk.
         // (do not append and UTF-8 are default, but we're defining it explicitly just in case)
         StreamWriter sw = new StreamWriter(xmlFile, false, System.Text.Encoding.UTF8);
         xml.Save(sw);
         sw.Close();
     }
     // We're done here.  If there were any failures, they would have returned false.
     // Return true to indicate success.
     return true;
 }
开发者ID:rahmanazhar,项目名称:UnityWorkspace,代码行数:42,代码来源:PListManager.cs

示例2: TestXmlDocumentAddXmlDeclaration

	// Test adding an XML declaration to the document.
	public void TestXmlDocumentAddXmlDeclaration()
			{
				XmlDocument doc = new XmlDocument();

				// Add the declaration.
				XmlDeclaration decl =
					doc.CreateXmlDeclaration("1.0", null, null);
				AssertNull("XmlDeclaration (1)", decl.ParentNode);
				AssertEquals("XmlDeclaration (2)", doc, decl.OwnerDocument);
				doc.AppendChild(decl);
				AssertEquals("XmlDeclaration (3)", doc, decl.ParentNode);
				AssertEquals("XmlDeclaration (4)", doc, decl.OwnerDocument);

				// Try to add it again, which should fail this time.
				try
				{
					doc.AppendChild(decl);
					Fail("adding XmlDeclaration node twice");
				}
				catch(InvalidOperationException)
				{
					// Success
				}
				try
				{
					doc.PrependChild(decl);
					Fail("prepending XmlDeclaration node twice");
				}
				catch(InvalidOperationException)
				{
					// Success
				}

				// Adding a document type before should fail.
				XmlDocumentType type =
					doc.CreateDocumentType("foo", null, null, null);
				try
				{
					doc.PrependChild(type);
					Fail("prepending XmlDocumentType");
				}
				catch(InvalidOperationException)
				{
					// Success
				}

				// Adding a document type after should succeed.
				doc.AppendChild(type);

				// Adding an element before should fail.
				XmlElement element = doc.CreateElement("foo");
				try
				{
					doc.PrependChild(element);
					Fail("prepending XmlElement");
				}
				catch(InvalidOperationException)
				{
					// Success
				}

				// Adding the element between decl and type should fail.
				try
				{
					doc.InsertAfter(element, decl);
					Fail("inserting XmlElement between XmlDeclaration " +
						 "and XmlDocumentType");
				}
				catch(InvalidOperationException)
				{
					// Success
				}
				try
				{
					doc.InsertBefore(element, type);
					Fail("inserting XmlElement between XmlDeclaration " +
						 "and XmlDocumentType (2)");
				}
				catch(InvalidOperationException)
				{
					// Success
				}

				// Adding an element after should succeed.
				doc.AppendChild(element);
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:87,代码来源:TestXmlDocument.cs

示例3: TestXmlDocumentAddElement

	// Test adding an element to the document.
	public void TestXmlDocumentAddElement()
			{
				XmlDocument doc = new XmlDocument();

				// Add an element to the document.
				XmlElement element = doc.CreateElement("foo");
				AssertNull("XmlElement (1)", element.ParentNode);
				AssertEquals("XmlElement (2)", doc, element.OwnerDocument);
				doc.AppendChild(element);
				AssertEquals("XmlElement (3)", doc, element.ParentNode);
				AssertEquals("XmlElement (4)", doc, element.OwnerDocument);

				// Try to add it again, which should fail this time.
				try
				{
					doc.AppendChild(element);
					Fail("adding XmlElement node twice");
				}
				catch(InvalidOperationException)
				{
					// Success
				}
				try
				{
					doc.PrependChild(element);
					Fail("prepending XmlElement node twice");
				}
				catch(InvalidOperationException)
				{
					// Success
				}

				// Adding an XmlDeclaration after should fail.
				XmlDeclaration decl =
					doc.CreateXmlDeclaration("1.0", null, null);
				try
				{
					doc.AppendChild(decl);
					Fail("appending XmlDeclaration after XmlElement");
				}
				catch(InvalidOperationException)
				{
					// Success
				}

				// But adding XmlDeclaration before should succeed.
				doc.PrependChild(decl);

				// Adding a document type after should fail.
				XmlDocumentType type =
					doc.CreateDocumentType("foo", null, null, null);
				try
				{
					doc.AppendChild(type);
					Fail("appending XmlDocumentType");
				}
				catch(InvalidOperationException)
				{
					// Success
				}

				// Adding a document type before should succeed.
				doc.InsertBefore(type, element);
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:65,代码来源:TestXmlDocument.cs

示例4: PostProcessBuild


//.........这里部分代码省略.........
        #endif

        // Add missing system frameworks
        AddSystemFramework(pbxproj, "CoreData");
        AddSystemFramework(pbxproj, "CoreTelephony");

        // Tweak build configurations
        var buildConfigurationListKey = targetNode
            .SelectSingleNode("key[text()=\"buildConfigurationList\"]/following-sibling::*[1]/text()")
            .Value;
        var buildConfigurationListNode = objectsNode.SelectSingleNode(
            string.Format("key[text()=\"{0}\"]/following-sibling::*[1]", buildConfigurationListKey));
        var buildConfigurationList =
            buildConfigurationListNode.SelectNodes("key[text()=\"buildConfigurations\"]/following-sibling::*[1]/string/text()");
        foreach (XmlNode buildConfigurationListEntry in buildConfigurationList)
        {
            var buildConfigurationKey = buildConfigurationListEntry.Value;
            var buildConfigurationNode = objectsNode.SelectSingleNode(
                string.Format("key[text()=\"{0}\"]/following-sibling::*[1]", buildConfigurationKey));

            var buildSettings =
                buildConfigurationNode.SelectSingleNode("key[text()=\"buildSettings\"]/following-sibling::*[1]");

            var otherLinkerFlagsNode = buildSettings.SelectSingleNode("key[text()=\"OTHER_LDFLAGS\"]/following-sibling::*[1]");
            if (otherLinkerFlagsNode == null)
            {
                buildSettings.AppendChildElement("key", "OTHER_LDFLAGS");
                otherLinkerFlagsNode = buildSettings.AppendChildElement("array");
            }

            // Add -ObjC flag to linker flags of the target
            var objCFlagNode = otherLinkerFlagsNode.SelectSingleNode("string[text()=\"-ObjC\"]");
            if (objCFlagNode == null)
                objCFlagNode = otherLinkerFlagsNode.AppendChildElement("string", "-ObjC");

            // Tweak Info.plist file to support deep-linking
            var infoPlistFilename =
                buildSettings.SelectSingleNode("key[text()=\"INFOPLIST_FILE\"]/following-sibling::*[1]/text()").Value;
            var infoPlistPath = Path.Combine(pathToBuiltProject, infoPlistFilename);
            var infoPlist = new XmlDocument();
            infoPlist.Load(infoPlistPath);

            var infoPlistContent = infoPlist.SelectSingleNode("plist/dict");
            var urlTypesNode = infoPlistContent.SelectSingleNode("key[text()=\"CFBundleURLTypes\"]/following-sibling::*[1]");
            if (urlTypesNode == null)
            {
                infoPlistContent.AppendChildElement("key", "CFBundleURLTypes");
                urlTypesNode = infoPlistContent.AppendChildElement("array");
            }

            var urlSchemeEntryNode = urlTypesNode.SelectSingleNode("dict[string=\"com.playseeds.unity3d.${PRODUCT_NAME}\"]");
            if (urlSchemeEntryNode == null)
            {
                urlSchemeEntryNode = urlTypesNode.AppendChildElement("dict");

                urlSchemeEntryNode.AppendChildElement("key", "CFBundleURLName");
                urlSchemeEntryNode.AppendChildElement("string", "com.playseeds.unity3d.${PRODUCT_NAME}");
            }

            var urlSchemeNode =
                urlSchemeEntryNode.SelectSingleNode("key[text()=\"CFBundleURLSchemes\"]//following-sibling::*[1]");
            if (urlSchemeNode == null)
            {
                urlSchemeEntryNode.AppendChildElement("key", "CFBundleURLSchemes");
                urlSchemeNode = urlSchemeEntryNode.AppendChildElement("array");
            }

            urlSchemeNode.RemoveAll();
            urlSchemeNode.AppendChildElement("string", scheme);

            if (infoPlist.DocumentType != null)
            {
                var name = infoPlist.DocumentType.Name;
                var publicId = infoPlist.DocumentType.PublicId;
                var systemId = infoPlist.DocumentType.SystemId;
                var parent = infoPlist.DocumentType.ParentNode;
                var documentTypeWithNullInternalSubset = infoPlist.CreateDocumentType(name, publicId, systemId, null);
                parent.ReplaceChild(documentTypeWithNullInternalSubset, infoPlist.DocumentType);
            }

            infoPlist.Save(infoPlistPath);
        }

        // Save pbxproj as XML and fix it
        var xmlWriterSettings = new XmlWriterSettings
        {
            Indent = false,
            NewLineHandling = NewLineHandling.None
        };
        using (var xmlWriter = XmlWriter.Create(pbxprojFilename, xmlWriterSettings))
        {
            pbxproj.Save(xmlWriter);
        }
        var pbxprojContent = File.ReadAllText(pbxprojFilename);
        pbxprojContent = pbxprojContent
            .Replace(
                "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"[]>",
                "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
        File.WriteAllText(pbxprojFilename, pbxprojContent);
    }
开发者ID:therealseeds,项目名称:seeds-sdk-unity,代码行数:101,代码来源:SeedsIntegration.cs


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