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


C# XmlTextWriter.WriteNode方法代碼示例

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


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

示例1: ParseHtml

        // Creates XmlDocument from html content and return it with rootitem "<root>".
        public static XmlDocument ParseHtml(string sContent)
        {
            StringReader sr = new StringReader("<root>" + sContent + "</root>");
            SgmlReader reader = new SgmlReader();
            reader.WhitespaceHandling = WhitespaceHandling.All;
            reader.CaseFolding = Sgml.CaseFolding.ToLower;
            reader.InputStream = sr;

            StringWriter sw = new StringWriter();
            XmlTextWriter w = new XmlTextWriter(sw);
            w.Formatting = Formatting.Indented;
            w.WriteStartDocument();
            reader.Read();
            while (!reader.EOF)
            {
                w.WriteNode(reader, true);
            }
            w.Flush();
            w.Close();

            sw.Flush();

            // create document
            XmlDocument doc = new XmlDocument();
            doc.PreserveWhitespace = true;
            doc.XmlResolver = null;
            doc.LoadXml(sw.ToString());

            reader.Close();

            return doc;
        }
開發者ID:Cabana,項目名稱:CMSConverter,代碼行數:33,代碼來源:SgmlUtil.cs

示例2: GetWellFormedHTML

 public static string GetWellFormedHTML(string html, string xpathNavPath)
 {
     // StreamReader sReader = null;
     StringWriter sw = null;
     SgmlReader reader = null;
     XmlTextWriter writer = null;
     try
     {
         //  if (uri == String.Empty) uri = "http://www.XMLforASP.NET";
         // HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
         //  HttpWebResponse res = (HttpWebResponse)req.GetResponse();
         //  sReader = new StreamReader(res.GetResponseStream());
         reader = new SgmlReader();
         reader.DocType = "HTML";
         reader.InputStream = new StringReader(html);
         sw = new StringWriter();
         writer = new XmlTextWriter(sw);
         writer.Formatting = Formatting.Indented;
         //writer.WriteStartElement("Test");
         while (reader.Read())
         {
             if (reader.NodeType != XmlNodeType.Whitespace)
             {
                 writer.WriteNode(reader, true);
             }
         }
         //writer.WriteEndElement();
         if (xpathNavPath == null)
         {
             string sr = sw.ToString();
             sr = sr.Replace("\r", "\n");
             sr = sr.Replace("\n\n", "\n");
             return sr;
         }
         else
         { //Filter out nodes from HTML
             StringBuilder sb = new StringBuilder();
             XPathDocument doc = new XPathDocument(new StringReader(sw.ToString()));
             XPathNavigator nav = doc.CreateNavigator();
             XPathNodeIterator nodes = nav.Select(xpathNavPath);
             while (nodes.MoveNext())
             {
                 sb.Append(nodes.Current.Value + "\n");
             }
             string sr = sb.ToString();
             sr = sr.Replace("\r", "\n");
             sr = sr.Replace("\n\n", "\n");
             return sr;
         }
     }
     catch (Exception exp)
     {
         writer.Close();
         reader.Close();
         sw.Close();
         // sReader.Close();
         return exp.Message;
     }
 }
開發者ID:drzo,項目名稱:opensim4opencog,代碼行數:59,代碼來源:HttpUtil.cs

示例3: Invoke

        /// <summary>
        /// Executes the command logics.
        /// </summary>
        public override void Invoke()
        {
            //print request xml
            var doc = new XmlDocument();
            var stringWriter = new StringWriter();

            //get your document
            try
            {
                doc.LoadXml(this.document.Text);
            }
            catch (Exception)
            {
                return;
            }

            //create reader and writer
            var xmlReader = new XmlNodeReader(doc);

            //set formatting options
            var xmlWriter = new XmlTextWriter(stringWriter)
                                {
                                    Formatting = Formatting.Indented,
                                    Indentation = 3,
                                    IndentChar = ' '
                                };

            //write the document formatted
            xmlWriter.WriteNode(xmlReader, true);

            this.document.Text = stringWriter.ToString();
        }
開發者ID:Waltervondehans,項目名稱:NBi,代碼行數:35,代碼來源:AutoIndentCommand.cs

示例4: TransformingTest

		public void TransformingTest() 
		{
			XslTransform tx = new XslTransform();
			tx.Load(new XmlTextReader(
				Globals.GetResource(this.GetType().Namespace + ".test.xsl")));

			XmlReader xtr = new XmlTransformingReader(
				new XmlTextReader(
				Globals.GetResource(this.GetType().Namespace + ".input.xml")),
				tx);

			//That's it, now let's dump out XmlTransformingReader to see what it returns
			StringWriter sw = new StringWriter();
			XmlTextWriter w = new XmlTextWriter(sw);
			w.Formatting = Formatting.Indented;
			w.WriteNode(xtr, false);
			xtr.Close();
			w.Close();

			Assert.AreEqual(sw.ToString(), @"<parts>
  <item SKU=""1001"" name=""Lawnmower"" price=""299.99"" />
  <item SKU=""1001"" name=""Electric drill"" price=""99.99"" />
  <item SKU=""1001"" name=""Hairdrier"" price=""39.99"" />
</parts>");
		}
開發者ID:zanyants,項目名稱:mvp.xml,代碼行數:25,代碼來源:Tests.cs

示例5: GenerateIndentedOuterXml

 public static string GenerateIndentedOuterXml(string xmlContent)
 {
     StringWriter buffer = new StringWriter();
     XmlTextWriter writer = new XmlTextWriter(buffer);
     writer.Formatting = Formatting.Indented;
     writer.WriteNode(new XmlTextReader(new StringReader(xmlContent)), false);
     return buffer.ToString();
 }
開發者ID:vardars,項目名稱:ci-factory,代碼行數:8,代碼來源:XmlUtil.cs

示例6: CreateSubdirectoryXML

        private static void CreateSubdirectoryXML(XmlTextWriter writer, DirectoryInfo dir)
        {
            string xml = new XElement("dir", new XAttribute("name", dir.Name)).ToString();
            XmlReader reader = XmlReader.Create(new StringReader(xml));
            writer.WriteNode(reader, true);

            foreach (var file in dir.GetFiles())
            {
                xml = new XElement("file", new XAttribute("name", file.Name)).ToString();
                reader = XmlReader.Create(new StringReader(xml));
                writer.WriteNode(reader, true);
            }

            var subdirectories = dir.GetDirectories().ToList().OrderBy(d => d.Name);
            foreach (var subDir in subdirectories)
            {
                CreateSubdirectoryXML(writer, subDir);
            }
        }
開發者ID:freemsly,項目名稱:DataBases,代碼行數:19,代碼來源:EntryPoint.cs

示例7: Indent

 /// <summary>
 /// Indents the specifide XML string.
 /// </summary>
 public static string Indent(this string xml)
 {
     var reder = new XmlTextReader(new StringReader(xml));
     var sw = new StringWriter();
     var xmlTextWriter = new XmlTextWriter(sw) {Formatting = Formatting.Indented};
     while (reder.Read())
         xmlTextWriter.WriteNode(reder, false);
     xmlTextWriter.Close();
     reder.Close();
     return sw.ToString();
 }
開發者ID:bdurrani,項目名稱:WPF-Inspector,代碼行數:14,代碼來源:XmlHelper.cs

示例8: GetTokenFormatted

        private static string GetTokenFormatted()
        {
            var sb = new StringBuilder();
            XmlTextWriter w = new XmlTextWriter(new StringWriter(sb));
            w.Formatting = Formatting.Indented;
            w.IndentChar = '\t';

            XmlReader reader = XmlReader.Create(new FileStream(Path.Combine(Application.StartupPath, "token.xml"), FileMode.Open));
            w.WriteNode(reader, true);
            w.Flush();
            return sb.ToString();
        }
開發者ID:kenbwhite,項目名稱:token-requestor,代碼行數:12,代碼來源:TokenRequestor.cs

示例9: SaveDocument

 public void SaveDocument(XmlDocument xmlDocument, string xmlFileName)
 {
     if (xmlDocument == null) throw new ArgumentNullException("xmlDocument");
     if (string.IsNullOrEmpty(xmlFileName)) throw new ArgumentNullException("xmlFileName");
     using (var xmlTextReader = new XmlTextReader(xmlDocument.OuterXml, XmlNodeType.Document, new XmlParserContext(null, null, null, XmlSpace.None)))
     {
         using (var xmlTextWriter = new XmlTextWriter(xmlFileName, Encoding.UTF8))
         {
             xmlTextWriter.Formatting = Formatting.Indented;
             xmlTextWriter.WriteNode(xmlTextReader, true);
             xmlTextWriter.Flush();
         }
     }
 }
開發者ID:trondr,項目名稱:NMultiTool,代碼行數:14,代碼來源:XmlHelper.cs

示例10: Main

        static void Main(string[] args)
        {
            bool showHelp = false;
            bool suppressOutput = false;

            var options = new OptionSet {
                { "s", v => suppressOutput = true },
                { "h|?|help", v => showHelp = true }
            };

            string filename = options.Parse(args).FirstOrDefault() ?? string.Empty;

            if (args.Length == 0 || showHelp)
            {
                PrintHelp();
                return;
            }

            if(!File.Exists(filename))
            {
                Console.Error.WriteLine("File {0} does not exist", filename);
                return;
            }

            XmlReader reader;
            TextWriter outputStream;

            if (suppressOutput)
            {
                // Suppress output
                reader = GetReader(filename);
                outputStream = TextWriter.Null;
            }
            else
            {
                reader = GetReader(filename);

                // Console.Out is a StreamWriter which flushes it's
                // buffer after every call to write. This is due to
                // setting AutoFlush to true. (according to the docs)

                // 256 should be the default buffer size
                Console.OpenStandardOutput(256);

                outputStream = Console.Out;
            }

            var writer = new XmlTextWriter(outputStream) {Formatting = Formatting.Indented};
            writer.WriteNode(reader, false);
        }
開發者ID:rbirkby,項目名稱:gedcomreader,代碼行數:50,代碼來源:Main.cs

示例11: TraceData

        public override void TraceData(System.Diagnostics.TraceEventCache eventCache, string source, System.Diagnostics.TraceEventType eventType, int id, object data)
        {
            // Get ActivityId from the eventCache.
            // ActivityId is an internal property. Using reflection to get its value
            string activityID = "";

            if (eventCache != null)
            {
                PropertyInfo propInfo = null;
                Type objType = eventCache.GetType();
                propInfo = objType.GetProperty("ActivityId", BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.NonPublic);
                if (propInfo != null)
                {
                    object value = propInfo.GetValue(eventCache, null);
                    if (value != null)
                        activityID = value.ToString();
                }
            }

            Process p = Process.GetProcessById(eventCache.ProcessId);
            // Header message that is added by this listener
            string msgHeader = string.Format("<HeaderAddedByListener time=\"{0}\" ActivityId=\"{1}\" ProcessId=\"{2}\">", eventCache.DateTime.ToString(), activityID, p.ProcessName);

            // Read the message received from wcf
            XPathNavigator xPathNavigator = data as XPathNavigator;
            if (xPathNavigator == null)
            {
                return;
            }

            XmlTextWriter xmlWriter;
            StringBuilder msgReceived = new StringBuilder();
            xmlWriter = new XmlTextWriter(new System.IO.StringWriter(msgReceived, CultureInfo.CurrentCulture));

            xPathNavigator.MoveToRoot();
            xmlWriter.WriteNode(xPathNavigator, false);

            // Broadcast the msg
            string msgToSend = string.Format("{0}{1}</HeaderAddedByListener>", msgHeader, msgReceived.ToString());
            GlobalHost.ConnectionManager.GetConnectionContext<ListenerConnection>().Connection.Broadcast(msgToSend);

            //base.TraceData(eventCache, source, eventType, id, data);

            if (xmlWriter != null)
            {
                xmlWriter.Close();
            }
            xmlWriter = null;
            msgReceived = null;
        }
開發者ID:SuganyaSinha,項目名稱:WCF-Live-Trace-Viewer,代碼行數:50,代碼來源:SignalRTraceListener.cs

示例12: XPathNodeIteratorToConsole

		public static void XPathNodeIteratorToConsole(XPathNodeIterator iterator)
		{
			Console.WriteLine(new string('-', 50));
			XmlTextWriter tw = new XmlTextWriter(Console.Out);
			tw.Formatting = Formatting.Indented;

			while (iterator.MoveNext())
			{
				tw.WriteNode(new Mvp.Xml.Common.XPath.XPathNavigatorReader(iterator.Current), false);
			}

			tw.Flush();
			Console.WriteLine();
			Console.WriteLine(new string('-', 50));
		}
開發者ID:zanyants,項目名稱:mvp.xml,代碼行數:15,代碼來源:DebugUtils.cs

示例13: Format

        //[STAThread]
        public static string Format(string s)
        {
            var stringWriter = new StringWriter();
            var doc = new XmlDocument();

            //get your document
            doc.LoadXml(s);

            //create reader and writer
            var xmlReader = new XmlNodeReader(doc);
            var xmlWriter = new XmlTextWriter(stringWriter) {Formatting = Formatting.Indented, Indentation = 2, IndentChar = ' '};

            //set formatting options

            //write the document formatted
            xmlWriter.WriteNode(xmlReader, true);
            return stringWriter.ToString();
        }
開發者ID:agray,項目名稱:WIXWriter,代碼行數:19,代碼來源:PrettyPrintFormatter.cs

示例14: Convert

        internal static void Convert(String htmlFile, String xhtmlFile)
        {
            using (SgmlReader reader = new SgmlReader()) {
                reader.DocType = "HTML";
                reader.WhitespaceHandling = WhitespaceHandling.None;

                using (StreamReader r = new StreamReader(htmlFile)) {
                    reader.InputStream = r;

                    using (XmlTextWriter writer = new XmlTextWriter(xhtmlFile, Encoding.UTF8)) {
                        writer.Formatting = Formatting.Indented;

                        reader.Read ();
                        while (!reader.EOF) {
                            writer.WriteNode (reader, true);
                        }
                    }
                }
            }
        }
開發者ID:Monobjc,項目名稱:monobjc-tools,代碼行數:20,代碼來源:Html2XhtmlTask.cs

示例15: TestRss

		public void TestRss()
		{
			string theWord = "XML";
			XPathDocument doc = new XPathDocument("../../Common/XPathIteratorReaderTests/rss.xml");
			XPathNodeIterator it = doc.CreateNavigator().Select(
				"/rss/channel/item[contains(title,'" + theWord + "')]");

			XPathIteratorReader reader = new XPathIteratorReader(it);
			reader.MoveToContent();
			string xml = reader.ReadOuterXml();

			using (StreamWriter sw = new StreamWriter(@"c:\subset.xml", false))
			{
				XmlTextWriter tw = new XmlTextWriter(sw);
				tw.WriteNode(new XPathIteratorReader(it), false);
				tw.Close();
			}

			Assert.IsTrue(xml != String.Empty);
		}
開發者ID:zanyants,項目名稱:mvp.xml,代碼行數:20,代碼來源:Tests.cs


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