當前位置: 首頁>>代碼示例>>C#>>正文


C# XmlDocument.CreateWhitespace方法代碼示例

本文整理匯總了C#中System.Xml.XmlDocument.CreateWhitespace方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlDocument.CreateWhitespace方法的具體用法?C# XmlDocument.CreateWhitespace怎麽用?C# XmlDocument.CreateWhitespace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.XmlDocument的用法示例。


在下文中一共展示了XmlDocument.CreateWhitespace方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Save

        public bool Save(string path)
        {
            bool saved = true;
            XmlDocument m_Xdoc = new XmlDocument();
            try
            {
                m_Xdoc.RemoveAll();

                XmlNode node = m_Xdoc.CreateXmlDeclaration("1.0", "utf-8", string.Empty);
                m_Xdoc.AppendChild(node);

                node = m_Xdoc.CreateComment($" Profile Configuration Data. {DateTime.Now} ");
                m_Xdoc.AppendChild(node);

                node = m_Xdoc.CreateWhitespace("\r\n");
                m_Xdoc.AppendChild(node);

                node = m_Xdoc.CreateNode(XmlNodeType.Element, "Profile", null);

                m_Xdoc.AppendChild(node);

                m_Xdoc.Save(path);
            }
            catch
            {
                saved = false;
            }

            return saved;
        }
開發者ID:SonicFreak94,項目名稱:DS4Windows,代碼行數:30,代碼來源:SaveWhere.cs

示例2: Save

        public void Save(Control murpleControl, string filename, PodGroup thisPodGroup)
        {
            StreamWriter streamWriter = new StreamWriter(filename);
            XmlWriter xmlWriter = XmlWriter.Create(streamWriter);

            XmlDocument document = new XmlDocument();
            document.AppendChild(document.CreateWhitespace("\n"));

            {
                XmlElement murpleElement = document.CreateElement("Murple");

                AddNewLine(document, murpleElement);

                foreach (KeyValuePair<System.Guid, Pod> thisPodPair in murpleControl.Pods)
                {
                    if(thisPodGroup.ContainsPod(thisPodPair.Key) == true)
                        AddPod(document, murpleElement, thisPodPair);
                }

                document.AppendChild(murpleElement);
            }

            document.Save(xmlWriter);
            streamWriter.Close();
        }
開發者ID:eugeneUG,項目名稱:Murple,代碼行數:25,代碼來源:MurpleLoader.cs

示例3: GetReady

		public void GetReady ()
		{
			document = new XmlDocument ();
			document.LoadXml ("<root><foo></foo></root>");
			XmlElement element = document.CreateElement ("foo");
			whitespace = document.CreateWhitespace ("\r\n");
			element.AppendChild (whitespace);

			doc2 = new XmlDocument ();
			doc2.PreserveWhitespace = true;
		}
開發者ID:jjenki11,項目名稱:blaze-chem-rendering,代碼行數:11,代碼來源:XmlWhiteSpaceTests.cs

示例4: ImportWhiteSpace

        public static void ImportWhiteSpace()
        {
            var whitespace = "        ";
            var tempDoc = new XmlDocument();
            var nodeToImport = tempDoc.CreateWhitespace(whitespace);

            var xmlDocument = new XmlDocument();
            var node = xmlDocument.ImportNode(nodeToImport, true);

            Assert.Equal(xmlDocument, node.OwnerDocument);
            Assert.Equal(XmlNodeType.Whitespace, node.NodeType);
            Assert.Equal(whitespace, node.Value);
        }
開發者ID:nandhanurrevanth,項目名稱:corefx,代碼行數:13,代碼來源:ImportNodeTests.cs

示例5: AddPolygonToSvg

        public void AddPolygonToSvg( XmlElement svgElement, XmlDocument htmlDoc )
        {
            XmlElement regionElement = htmlDoc.CreateElement ("g");

            var regionNameAttr = htmlDoc.CreateAttribute("name");
            regionNameAttr.Value = Name;
            regionElement.Attributes.Append (regionNameAttr);
            var regionClassAttr = htmlDoc.CreateAttribute ("class");
            regionClassAttr.Value = "PoliticalRegion";
            regionElement.Attributes.Append (regionClassAttr);

            // Shape
            for (int iSubRegion = 0; iSubRegion < Geometry.NumGeometries; iSubRegion += 1) {
                var subRegionNode = htmlDoc.CreateElement ("polygon");

                // Define subregion border.
                var subRegion = Geometry.GetGeometryN (iSubRegion);
                var coords = subRegion.Coordinates;
                var coordStrings = coords.Select (coord => string.Format ("{0:F2},{1:F2} ", coord.X, -coord.Y));
                string coordString = coordStrings.Aggregate ((coordStringBase, coordStringNext) => coordStringBase + coordStringNext);
                var pointsAttr = htmlDoc.CreateAttribute ("points");
                pointsAttr.Value = coordString;
                subRegionNode.Attributes.Append(pointsAttr);

                // Color/Style spec.
                var styleAttr = htmlDoc.CreateAttribute ("style");
                styleAttr.Value = StyleSpec;
                subRegionNode.Attributes.Append(styleAttr);

                // Add state polygon, text to list
                regionElement.AppendChild (htmlDoc.CreateWhitespace ("\n"));
                regionElement.AppendChild (subRegionNode);

            }
            // Add state polygon, text to list
            svgElement.AppendChild (htmlDoc.CreateWhitespace ("\n"));
            svgElement.AppendChild (regionElement);
        }
開發者ID:jasonstewartnz,項目名稱:UsStateVisualizer,代碼行數:38,代碼來源:PoliticalRegion.cs

示例6: CreateNode

        public static XmlNode CreateNode(XmlDocument doc, XmlNodeType nodeType)
        {
            Assert.NotNull(doc);

            switch (nodeType)
            {
                case XmlNodeType.CDATA:
                    return doc.CreateCDataSection(@"&lt; &amp; <tag> < ! > & </tag> 	 ");
                case XmlNodeType.Comment:
                    return doc.CreateComment(@"comment");
                case XmlNodeType.Element:
                    return doc.CreateElement("E");
                case XmlNodeType.Text:
                    return doc.CreateTextNode("text");
                case XmlNodeType.Whitespace:
                    return doc.CreateWhitespace(@"	  ");
                case XmlNodeType.SignificantWhitespace:
                    return doc.CreateSignificantWhitespace("	");
                default:
                    throw new ArgumentException("Wrong XmlNodeType: '" + nodeType + "'");
            }
        }
開發者ID:nnyamhon,項目名稱:corefx,代碼行數:22,代碼來源:TestHelper.cs

示例7: DeserializeValue

    private void DeserializeValue(JsonReader reader, XmlDocument document, XmlNamespaceManager manager, string propertyName, XmlNode currentNode)
    {
      switch (propertyName)
      {
        case TextName:
          currentNode.AppendChild(document.CreateTextNode(reader.Value.ToString()));
          break;
        case CDataName:
          currentNode.AppendChild(document.CreateCDataSection(reader.Value.ToString()));
          break;
        case WhitespaceName:
          currentNode.AppendChild(document.CreateWhitespace(reader.Value.ToString()));
          break;
        case SignificantWhitespaceName:
          currentNode.AppendChild(document.CreateSignificantWhitespace(reader.Value.ToString()));
          break;
        default:
          // processing instructions and the xml declaration start with ?
          if (!string.IsNullOrEmpty(propertyName) && propertyName[0] == '?')
          {
            if (propertyName == DeclarationName)
            {
              string version = null;
              string encoding = null;
              string standalone = null;
              while (reader.Read() && reader.TokenType != JsonToken.EndObject)
              {
                switch (reader.Value.ToString())
                {
                  case "@version":
                    reader.Read();
                    version = reader.Value.ToString();
                    break;
                  case "@encoding":
                    reader.Read();
                    encoding = reader.Value.ToString();
                    break;
                  case "@standalone":
                    reader.Read();
                    standalone = reader.Value.ToString();
                    break;
                  default:
                    throw new JsonSerializationException("Unexpected property name encountered while deserializing XmlDeclaration: " + reader.Value);
                }
              }

              XmlDeclaration declaration = document.CreateXmlDeclaration(version, encoding, standalone);
              currentNode.AppendChild(declaration);
            }
            else
            {
              XmlProcessingInstruction instruction = document.CreateProcessingInstruction(propertyName.Substring(1), reader.Value.ToString());
              currentNode.AppendChild(instruction);
            }
          }
          else
          {
            // deserialize xml element
            bool finishedAttributes = false;
            bool finishedElement = false;
            string elementPrefix = GetPrefix(propertyName);
            Dictionary<string, string> attributeNameValues = new Dictionary<string, string>();

            // a string token means the element only has a single text child
            if (reader.TokenType != JsonToken.String
              && reader.TokenType != JsonToken.Null
              && reader.TokenType != JsonToken.Boolean
              && reader.TokenType != JsonToken.Integer
              && reader.TokenType != JsonToken.Float
              && reader.TokenType != JsonToken.Date
              && reader.TokenType != JsonToken.StartConstructor)
            {
              // read properties until first non-attribute is encountered
              while (!finishedAttributes && !finishedElement && reader.Read())
              {
                switch (reader.TokenType)
                {
                  case JsonToken.PropertyName:
                    string attributeName = reader.Value.ToString();

                    if (attributeName[0] == '@')
                    {
                      attributeName = attributeName.Substring(1);
                      reader.Read();
                      string attributeValue = reader.Value.ToString();
                      attributeNameValues.Add(attributeName, attributeValue);

                      string namespacePrefix;

                      if (IsNamespaceAttribute(attributeName, out namespacePrefix))
                      {
                        manager.AddNamespace(namespacePrefix, attributeValue);
                      }
                    }
                    else
                    {
                      finishedAttributes = true;
                    }
                    break;
                  case JsonToken.EndObject:
//.........這裏部分代碼省略.........
開發者ID:matthewcanty,項目名稱:worldpay-lib-dotnet,代碼行數:101,代碼來源:XmlNodeConverter.cs

示例8: Detokenize

        private static int Detokenize(Tuplet<ArrayDiffKind, Token>[] tokens, int index, XmlElement current, XmlDocument doc)
        {
            for(; index < tokens.Length; ++index) {
                Tuplet<ArrayDiffKind, Token> token = tokens[index];
                switch(token.Item1) {
                case ArrayDiffKind.Same:
                case ArrayDiffKind.Added:
                    switch(token.Item2.Type) {
                    case XmlNodeType.CDATA:
                        if(current == null) {
                            throw new ArgumentNullException("current");
                        }
                        current.AppendChild(doc.CreateCDataSection(token.Item2.Value));
                        break;
                    case XmlNodeType.Comment:
                        if(current == null) {
                            throw new ArgumentNullException("current");
                        }
                        current.AppendChild(doc.CreateComment(token.Item2.Value));
                        break;
                    case XmlNodeType.SignificantWhitespace:
                        if(current == null) {
                            throw new ArgumentNullException("current");
                        }
                        current.AppendChild(doc.CreateSignificantWhitespace(token.Item2.Value));
                        break;
                    case XmlNodeType.Text:
                        if(current == null) {
                            throw new ArgumentNullException("current");
                        }
                        current.AppendChild(doc.CreateTextNode(token.Item2.Value));
                        break;
                    case XmlNodeType.Whitespace:
                        if(current == null) {
                            throw new ArgumentNullException("current");
                        }
                        current.AppendChild(doc.CreateWhitespace(token.Item2.Value));
                        break;
                    case XmlNodeType.Element:
                        XmlElement next = doc.CreateElement(token.Item2.Value);
                        if(current == null) {
                            doc.AppendChild(next);
                        } else {
                            current.AppendChild(next);
                        }
                        index = Detokenize(tokens, index + 1, next, doc);
                        break;
                    case XmlNodeType.Attribute:
                        if(current == null) {
                            throw new ArgumentNullException("current");
                        }
                        string[] parts = token.Item2.Value.Split(new char[] { '=' }, 2);
                        current.SetAttribute(parts[0], parts[1]);
                        break;
                    case XmlNodeType.EndElement:

                        // nothing to do
                        break;
                    case XmlNodeType.None:
                        if(current == null) {
                            throw new ArgumentNullException("current");
                        }

                        // ensure we're closing the intended element
                        if(token.Item2.Value != current.Name) {
                            throw new InvalidOperationException(string.Format("mismatched element ending; found </{0}>, expected </{1}>", token.Item2.Value, current.Name));
                        }

                        // we're done with this sequence
                        return index;
                    default:
                        throw new InvalidOperationException("unhandled node type: " + token.Item2.Type);
                    }
                    break;
                case ArrayDiffKind.Removed:

                    // ignore removed nodes
                    break;
                default:
                    throw new InvalidOperationException("invalid diff kind: " + token.Item1);
                }
            }
            if(current != null) {
                throw new InvalidOperationException("unexpected end of tokens");
            }
            return index;
        }
開發者ID:sdether,項目名稱:DReAM,代碼行數:87,代碼來源:XDocDiff.cs

示例9: GetSnapshot

        /**
         * Reply to the http request
         */
        public XmlDocument GetSnapshot(string regionName)
        {
            CheckStale();

            XmlDocument requestedSnap = new XmlDocument();
            requestedSnap.AppendChild(requestedSnap.CreateXmlDeclaration("1.0", null, null));
            requestedSnap.AppendChild(requestedSnap.CreateWhitespace("\r\n"));

            XmlNode regiondata = requestedSnap.CreateNode(XmlNodeType.Element, "regiondata", "");
            try
            {
                if (string.IsNullOrEmpty(regionName))
                {
                    XmlNode timerblock = requestedSnap.CreateNode(XmlNodeType.Element, "expire", "");
                    timerblock.InnerText = m_period.ToString();
                    regiondata.AppendChild(timerblock);

                    regiondata.AppendChild(requestedSnap.CreateWhitespace("\r\n"));
                    foreach (Scene scene in m_scenes)
                    {
                        regiondata.AppendChild(m_snapStore.GetScene(scene, requestedSnap));
                    }
                }
                else
                {
                    Scene scene = SceneForName(regionName);
                    regiondata.AppendChild(m_snapStore.GetScene(scene, requestedSnap));
                }
                requestedSnap.AppendChild(regiondata);
                regiondata.AppendChild(requestedSnap.CreateWhitespace("\r\n"));
            }
            catch (XmlException e)
            {
                m_log.Warn("[DATASNAPSHOT]: XmlException while trying to load snapshot: " + e.ToString());
                requestedSnap = GetErrorMessage(regionName, e);
            }
            catch (Exception e)
            {
                m_log.Warn("[DATASNAPSHOT]: Caught unknown exception while trying to load snapshot: " + e.StackTrace);
                requestedSnap = GetErrorMessage(regionName, e);
            }


            return requestedSnap;
        }
開發者ID:CassieEllen,項目名稱:opensim,代碼行數:48,代碼來源:DataSnapshotManager.cs

示例10: AsText_on_element_concats_whitespace_text_significant_whitespace_and_CDATA

 public void AsText_on_element_concats_whitespace_text_significant_whitespace_and_CDATA()
 {
     var document = new XmlDocument();
     document.AppendChild(document.CreateElement("test"));
     var x = document.CreateElement("x");
     document.DocumentElement.AppendChild(x);
     x.AppendChild(document.CreateTextNode("foo"));
     x.AppendChild(document.CreateWhitespace(" "));
     x.AppendChild(document.CreateCDataSection("bar"));
     x.AppendChild(document.CreateSignificantWhitespace(" "));
     var doc = new XDoc(document);
     Assert.AreEqual("foo bar ", doc["x"].AsText);
 }
開發者ID:sdether,項目名稱:DReAM,代碼行數:13,代碼來源:XDoc-Test.cs

示例11: CreateAction

		private void CreateAction()
		{
			XmlDocument document = new XmlDocument();

			XmlNode node = document.CreateXmlDeclaration("1.0", "utf-8", string.Empty);
			document.AppendChild(node);

			node = document.CreateComment($" Special Actions Configuration Data. {DateTime.Now} ");
			document.AppendChild(node);

			node = document.CreateWhitespace("\r\n");
			document.AppendChild(node);

			node = document.CreateNode(XmlNodeType.Element, "Actions", string.Empty);
			document.AppendChild(node);
			document.Save(m_Actions);
		}
開發者ID:SonicFreak94,項目名稱:DS4Windows,代碼行數:17,代碼來源:ScpUtil.cs

示例12: SetPropertyValue

        private bool SetPropertyValue(XmlDocument xmlDoc, string PropertyName, string NewValue)
        {
            XmlNode parentNode = xmlDoc.DocumentElement.SelectSingleNode("appSettings");

            if (parentNode == null)
            {
                parentNode = xmlDoc.CreateElement("appSettings");
                xmlDoc.DocumentElement.AppendChild(xmlDoc.CreateWhitespace("\r\n  "));
                xmlDoc.DocumentElement.AppendChild(parentNode);
                xmlDoc.DocumentElement.AppendChild(xmlDoc.CreateWhitespace("\r\n"));
            }

            return XmlHelper.SetPropertyValue(xmlDoc, PropertyName, NewValue, parentNode, "add", "key", "value");
        }
開發者ID:Davincier,項目名稱:openpetra,代碼行數:14,代碼來源:ClientAutoLogOn.cs

示例13: AsText_on_whitespace_should_return_value

 public void AsText_on_whitespace_should_return_value()
 {
     var document = new XmlDocument();
     document.AppendChild(document.CreateElement("test"));
     var x = document.CreateElement("x");
     document.DocumentElement.AppendChild(x);
     x.AppendChild(document.CreateWhitespace(" "));
     var doc = new XDoc(document);
     Assert.AreEqual(" ", doc["x"][0].AsText);
 }
開發者ID:sdether,項目名稱:DReAM,代碼行數:10,代碼來源:XDoc-Test.cs

示例14: Page_Load

		private void Page_Load(object sender, System.EventArgs e)
		{
			Response.ExpiresAbsolute = new DateTime(1980, 1, 1, 0, 0, 0, 0);
			Response.CacheControl    = "no-cache";

			XmlDocument xml = new XmlDocument();
			xml.PreserveWhitespace = true;
			xml.AppendChild(xml.CreateXmlDeclaration("1.0", "UTF-8", null));
			xml.AppendChild(xml.CreateWhitespace("\n"));
			XmlNode xConnector = xml.CreateElement("Connector");
			xml.AppendChild(xConnector);
			try
			{
				string sCommand       = Sql.ToString(Request["Command"      ]);
				string sResourceType  = Sql.ToString(Request["Type"         ]);
				string sCurrentFolder = Sql.ToString(Request["CurrentFolder"]);

				if ( !Security.IsAuthenticated() )
				{
					xConnector.AppendChild(xml.CreateWhitespace("\n\t"));
					XmlUtil.SetSingleNodeAttribute(xml, "Error", "number", "1");
					XmlUtil.SetSingleNodeAttribute(xml, "Error", "text"  , "Authentication is required.");
					xConnector.AppendChild(xml.CreateWhitespace("\n"));
				}
				else if ( Sql.IsEmptyString(sCommand) || Sql.IsEmptyString(sResourceType) || Sql.IsEmptyString(sCurrentFolder) )
				{
					xConnector.AppendChild(xml.CreateWhitespace("\n\t"));
					XmlUtil.SetSingleNodeAttribute(xml, "Error", "number", "1");
					XmlUtil.SetSingleNodeAttribute(xml, "Error", "text"  , "Invalid request.");
					xConnector.AppendChild(xml.CreateWhitespace("\n"));
				}
				else
				{
					string sSiteURL = Utils.MassEmailerSiteURL(Context.Application);
					string sFileURL = sSiteURL + "Images/EmailImage.aspx?ID=";
					switch ( sCommand )
					{
						case "FileUpload":
						{
							int nErrorNumber = 0;
							string sFileName  = String.Empty;
							string sCustomMsg = String.Empty;
							Guid   gImageID   = Guid.Empty;
							
							DbProviderFactory dbf = DbProviderFactories.GetFactory();
							using ( IDbConnection con = dbf.CreateConnection() )
							{
								con.Open();
								// 10/07/2009   We need to create our own global transaction ID to support auditing and workflow on SQL Azure, PostgreSQL, Oracle, DB2 and MySQL. 
								using ( IDbTransaction trn = Sql.BeginTransaction(con) )
								{
									try
									{
										FileWorkerUtils.LoadImage(ref gImageID, ref sFileName, trn);
										if ( Sql.IsEmptyGuid(gImageID) )
											nErrorNumber = 202;
										else
											sFileURL += gImageID.ToString();
										trn.Commit();
									}
									catch
									{
										trn.Rollback();
										throw;
									}
								}
							}
							
							Response.Write("<script type=\"text/javascript\">\n");
							Response.Write("window.parent.frames['frmUpload'].OnUploadCompleted(" + nErrorNumber.ToString() + ",'" + Sql.EscapeJavaScript(sFileURL) + "','" + Sql.EscapeJavaScript(sFileName) + "','" + Sql.EscapeJavaScript(sCustomMsg) + "');\n");
							Response.Write("</script>\n");
							return;
						}
						case "GetFolders":
						{
							XmlUtil.SetSingleNodeAttribute(xml, xConnector, "command"     , sCommand     );
							XmlUtil.SetSingleNodeAttribute(xml, xConnector, "resourceType", sResourceType);
							xConnector.AppendChild(xml.CreateWhitespace("\n\t"));
							
							XmlUtil.SetSingleNodeAttribute(xml, "CurrentFolder", "path"        , sCurrentFolder);
							XmlUtil.SetSingleNodeAttribute(xml, "CurrentFolder", "url"         , sFileURL      );
							xConnector.AppendChild(xml.CreateWhitespace("\n\t"));
							
							XmlUtil.SetSingleNode         (xml, "Folders"      , "");
							xConnector.AppendChild(xml.CreateWhitespace("\n"));
							break;
						}
						case "GetFoldersAndFiles":
						{
							XmlUtil.SetSingleNodeAttribute(xml, xConnector, "command"     , sCommand     );
							XmlUtil.SetSingleNodeAttribute(xml, xConnector, "resourceType", sResourceType);
							xConnector.AppendChild(xml.CreateWhitespace("\n\t"));
							
							XmlUtil.SetSingleNodeAttribute(xml, "CurrentFolder", "path"        , sCurrentFolder);
							XmlUtil.SetSingleNodeAttribute(xml, "CurrentFolder", "url"         , sFileURL      );
							xConnector.AppendChild(xml.CreateWhitespace("\n\t"));
							
							XmlUtil.SetSingleNode         (xml, "Folders"      , "");
							xConnector.AppendChild(xml.CreateWhitespace("\n\t"));
							
//.........這裏部分代碼省略.........
開發者ID:huamouse,項目名稱:Taoqi,代碼行數:101,代碼來源:Connector.cs

示例15: AddNewLine

 private void AddNewLine(XmlDocument document, XmlElement targetElement)
 {
     targetElement.AppendChild(document.CreateWhitespace("\n"));
 }
開發者ID:eugeneUG,項目名稱:Murple,代碼行數:4,代碼來源:MurpleLoader.cs


注:本文中的System.Xml.XmlDocument.CreateWhitespace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。