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


C# XmlDocument.WriteTo方法代码示例

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


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

示例1: GetSpeaking_PracticeContents

    public List<string> GetSpeaking_PracticeContents(int ID_Unit)
    {
        IEnumerable<SPEAKING> speaking_Practices = this.GetSpeakingUnit(ID_Unit);

        List<string> list = new List<string>();

        foreach (SPEAKING item in speaking_Practices)
        {
            XmlDocument xmlDoc = new XmlDocument();
            Stream stream;
            try
            {
                stream = File.OpenRead(System.Web.Hosting.HostingEnvironment.MapPath("~/ClientBin/" + item.Suggestion));                
                xmlDoc.Load(stream);                
            }
            catch (XmlException e)
            {
                Console.WriteLine(e.Message);
            }
            // Now create StringWriter object to get data from xml document.
            StringWriter sw = new StringWriter();
            XmlTextWriter xw = new XmlTextWriter(sw);

            xmlDoc.WriteTo(xw);
            list.Add(sw.ToString());

        }

        return list;        
    }
开发者ID:mylgoehy,项目名称:qlqtpmav10,代码行数:30,代码来源:SpeakingService.cs

示例2: btnLahetaPalaute_Click

    protected void btnLahetaPalaute_Click(object sender, EventArgs e)
    {
        string filename = MapPath("~/App_Data/Palautteet.xml");

        XmlDocument doc = new XmlDocument();

        doc.Load(filename);

        XmlElement newElem = doc.CreateElement("palaute");

        newElem.InnerXml = "<pvm>" + this.tbxPvm.Text + "</pvm>" +
            "<tekija>" + this.tbxNimi.Text + "</tekija>" +
            "<opittu>" + this.tbxOlenOppinut.Text + "</opittu>" +
            "<haluanoppia>" + this.tbxHaluanOppia.Text + "</haluanoppia>" +
            "<hyvaa>" + this.tbxHyvaa.Text + "</hyvaa>" +
            "<parannettavaa>" + this.tbxHuonoa.Text + "</parannettavaa>" +
            "<muuta>" + this.tbxMuuta.Text + "</muuta>";

        doc.DocumentElement.SelectNodes("/palautteet")[0].AppendChild(newElem);

        XmlWriter w = new XmlTextWriter(filename, System.Text.Encoding.UTF8);
        doc.WriteTo(w);
        w.Close();

        this.tbxPvm.Text = "";
        this.tbxNimi.Text = "";
        this.tbxOlenOppinut.Text = "";
        this.tbxHaluanOppia.Text = "";
        this.tbxHyvaa.Text = "";
        this.tbxHuonoa.Text = "";
        this.tbxMuuta.Text = "";
    }
开发者ID:JuusoVoimala,项目名称:viikkotehtava-1,代码行数:32,代码来源:OpintojaksonPalaute.aspx.cs

示例3: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        XmlDocument xml = new XmlDocument();
        DataTable dt = CreateDataSource();
        DataSet ds = new DataSet("testDS");
        ds.Tables.Add(dt);
        xml.LoadXml(ds.GetXml());

        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.ContentType = "text/xml ";
        HttpContext.Current.Response.Charset = "UTF-8 ";
        XmlTextWriter writer = new XmlTextWriter(HttpContext.Current.Response.OutputStream, System.Text.Encoding.UTF8);
        writer.Formatting = Formatting.Indented;
        xml.WriteTo(writer);
        writer.Flush();
        HttpContext.Current.Response.End();
    }
开发者ID:vinStar,项目名称:vin_zone_2009,代码行数:17,代码来源:showXML.aspx.cs

示例4: DeleteByKey

 /// <summary>
 /// 删除[appSettings]节点中包含Key值的子节点,返回成功与否布尔值
 /// </summary>
 /// <param name="configurationFile">要操作的配置文件名称,枚举常量</param>
 /// <param name="key">要删除的子节点Key值</param>
 /// <returns>返回成功与否布尔值</returns>
 public static bool DeleteByKey(ConfigurationFile configurationFile, string key)
 {
     bool isSuccess = false;
     string filename = string.Empty;
     if (configurationFile.ToString() == ConfigurationFile.AppConfig.ToString())
     {
         filename = System.Windows.Forms.Application.ExecutablePath + ".config";
     }
     else
     {
         filename = System.AppDomain.CurrentDomain.BaseDirectory + "web.config";
     }
     XmlDocument doc = new XmlDocument();
     doc.Load(filename); //加载配置文件
     XmlNode node = doc.SelectSingleNode("//appSettings");   //得到[appSettings]节点
     ////得到[appSettings]节点中关于Key的子节点
     XmlElement element = (XmlElement)node.SelectSingleNode("//add[@key='" + key + "']");
     if (element != null)
     {
         //存在则删除子节点
         element.ParentNode.RemoveChild(element);
     }
     else
     {
         //不存在
     }
     try
     {
         //保存至配置文件(方式一)
         using (XmlTextWriter xmlwriter = new XmlTextWriter(filename, null))
         {
             xmlwriter.Formatting = Formatting.Indented;
             doc.WriteTo(xmlwriter);
             xmlwriter.Flush();
         }
         isSuccess = true;
     }
     catch (Exception ex)
     {
         isSuccess = false;
     }
     return isSuccess;
 }
开发者ID:hj-nicholas,项目名称:BaseFrame,代码行数:49,代码来源:ConfigHelper.cs

示例5: CreateSomeXml

    // Create example data to sign.
    public static void CreateSomeXml(string FileName)
    {
        // Create a new XmlDocument object.
        XmlDocument document = new XmlDocument();

        // Create a new XmlNode object.
        XmlNode node = document.CreateNode(XmlNodeType.Element, "", "MyElement", "samples");

        // Add some text to the node.
        node.InnerText = "Example text to be signed.";

        // Append the node to the document.
        document.AppendChild(node);

        // Save the XML document to the file name specified.
        XmlTextWriter xmltw = new XmlTextWriter(FileName, new UTF8Encoding(false));
        document.WriteTo(xmltw);
        xmltw.Close();
    }
开发者ID:Mahendrasiddappa,项目名称:Binary_server,代码行数:20,代码来源:program-repro-misc-validation-and-canon.cs

示例6: FormatXMLString

 public static string FormatXMLString(string sUnformattedXML)
 {
     XmlDocument xd = new XmlDocument();
     xd.LoadXml(sUnformattedXML);
     StringBuilder sb = new StringBuilder();
     StringWriter sw = new StringWriter(sb);
     XmlTextWriter xtw = null;
     try
     {
         xtw = new XmlTextWriter(sw);
         xtw.Formatting = Formatting.Indented;
         xd.WriteTo(xtw);
     }
     finally
     {
         if (xtw != null)
             xtw.Close();
     }
     return sb.ToString();
 }
开发者ID:dcolonvizi,项目名称:ViziAppsPortal,代码行数:20,代码来源:ShowXmlDesign.aspx.cs

示例7: WriteTableauXmlFile

    /// <summary>
    /// Output an XML file in the format that Tableau expects
    /// </summary>
    /// <param name="xmlDoc"></param>
    /// <param name="pathToOutput"></param>
    public static void WriteTableauXmlFile(XmlDocument xmlDoc, string pathToOutput)
    {
        //[2015-03-20]   Presently Server will error if it gets a TWB (XML) document uploaded that has a Byte Order Marker
        //                  (this will however work if the TWB is within a TWBX).  
        //                  To accomodate we need to write out XML without a BOM
        var utf8_noBOM = new System.Text.UTF8Encoding(false);
        using (var textWriter = new XmlTextWriter(pathToOutput, utf8_noBOM))                   
        {
            xmlDoc.WriteTo(textWriter);
            textWriter.Close();
        }

        //Write out the modified XML
//        var textWriter = new XmlTextWriter(_pathToTwbOutput, Encoding.UTF8);  //[2015-03-20] FAILS in TWB uploads (works in TWBX uploads) because Server errrors if it hits the byte order marker
//        var textWriter = new XmlTextWriter(_pathToTwbOutput, Encoding.ASCII); //[2015-03-20] Succeeds; but too limiting.  We want UTF-8
//        using (textWriter)
//        {
//            xmlDoc.WriteTo(textWriter);
//            textWriter.Close();
//        }
    }
开发者ID:yaswanth369,项目名称:TabMigrate,代码行数:26,代码来源:TableauPersistFileHelper.cs

示例8: XmlDocument

	void IXmlSerializable.WriteXml (XmlWriter writer)
	{
		XmlDocument doc = new XmlDocument ();
		doc.LoadXml (mFuncXmlNode.OuterXml);

		// On function level
		if (doc.DocumentElement.Name == "Func") {
			try { doc.DocumentElement.Attributes.Remove (doc.DocumentElement.Attributes ["ReturnType"]); } catch { }
			try { doc.DocumentElement.Attributes.Remove (doc.DocumentElement.Attributes ["ReturnTId"]); } catch { }
			try { doc.DocumentElement.Attributes.Remove (doc.DocumentElement.Attributes ["CSharpType"]); } catch { }
		} else {
			UpgradeSchema (doc.DocumentElement);
		}

		// Make sure lrt is saved according to latest schema
		foreach (XmlNode n in doc.DocumentElement.ChildNodes) {
			UpgradeSchema (n);
		}

		doc.WriteTo (writer);
	}
开发者ID:mono,项目名称:gert,代码行数:21,代码来源:test.cs

示例9: Main

 public static void Main( string[] args ) {
     if ( args.Length != 2 ) {
         return;
     }
     string indir = args[0];
     string outdir = args[1];
     if ( !Directory.Exists( indir ) || !Directory.Exists( outdir ) ) {
         Console.WriteLine( "error; directory not exists" );
         return;
     }
     
     List<string> files = new List<string>( Directory.GetFiles( "*.htm" ) );
     files.AddRange( Directory.GetFiles( "*.html" ) );
     foreach ( string name in files ) {
         string path = Path.Combine( indir, name );
         XmlDocument doc = new XmlDocument();
         doc.Load( path );
         XmlTextWriter xtw = new XmlTextWriter( new FileStream( Path.Combine( outdir, name ), FileMode.OpenOrCreate, FileAccess.Write ), System.Text.Encoding.GetEncoding( "Shift_JIS" ) );
         doc.WriteTo( xtw );
         xtw.Close();
     }
 }
开发者ID:cadencii,项目名称:cadencii,代码行数:22,代码来源:SandBox.cs

示例10: btnLahetaPalaute_Click

    protected void btnLahetaPalaute_Click(object sender, EventArgs e)
    {
        XmlDocument doc = new XmlDocument();
        doc.Load(MapPath("~/App_Data/Palautteet.xml"));

        XmlElement newElem = doc.CreateElement("palaute");

        string dateNow = Convert.ToString(DateTime.Today.ToShortDateString());
        newElem.InnerXml = "<pvm>" + dateNow + "</pvm>" +
            "<tekija>" + this.txtNimi.Text + "</tekija>" +
            "<opittu>" + this.txtOppinut.Text + "</opittu>" +
            "<haluanoppia>" + this.txtHaluan.Text + "</haluanoppia>" +
            "<hyvaa>" + this.txtHyvaa.Text + "</hyvaa>" +
            "<parannettavaa>" + this.txtParannettavaa.Text + "</parannettavaa>" +
            "<muuta>" + this.txtMuuta.Text + "</muuta>";

        doc.DocumentElement.SelectNodes("/palautteet")[0].AppendChild(newElem);

        XmlTextWriter wrtr = new XmlTextWriter(MapPath("~/App_Data/Palautteet.xml"), System.Text.Encoding.UTF8);
        doc.WriteTo(wrtr);
        wrtr.Close();
    }
开发者ID:vebzical,项目名称:viikkotehtava-1,代码行数:22,代码来源:g2456_ValiPalaute.aspx.cs

示例11: Write

    public String Write(Environment env)
    {
        XmlDocument xmlDoc = new XmlDocument ();
        string basexml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
        <eeml xmlns=""http://www.eeml.org/xsd/0.5.1""
              xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" version=""0.5.1""
              xsi:schemaLocation=""http://www.eeml.org/xsd/0.5.1 http://www.eeml.org/xsd/0.5.1/0.5.1.xsd""></eeml>";
        xmlDoc.LoadXml (basexml);
        XmlNode root = xmlDoc.DocumentElement;

        //It seems we must explicitly specify each node's namespace
        //If we leave ns out, it won't just inherit from parent re ns but will say xmlns=""
        XmlElement nEnv = xmlDoc.CreateElement ("environment",xmlDoc.DocumentElement.NamespaceURI);

        //Add the node to the document.
        root.AppendChild (nEnv);
        nEnv.SetAttribute ("id", env.id);
        nEnv.AppendChild (UtilSimpleTextNode (xmlDoc, "title", env.title));
        nEnv.AppendChild (UtilSimpleTextNode (xmlDoc, "description", env.description));
        nEnv.AppendChild (UtilSimpleTextNode (xmlDoc, "website", env.website));
        nEnv.AppendChild (MakeLocationXML (env.location, xmlDoc));
        foreach (String tag in env.tags) {
            nEnv.AppendChild (UtilSimpleTextNode (xmlDoc, "tag", tag));
        }
        foreach (Datastream ds in env.datastreams) {
            nEnv.AppendChild (MakeDatastreamXML (ds, xmlDoc));
        }

        // Now create StringWriter object to get data from xml document.
        StringWriter sw = new StringWriter ();
        XmlTextWriter xw = new XmlTextWriter (sw);
        xw.Formatting = Formatting.Indented;
        xw.Indentation = 4;
        xmlDoc.WriteTo (xw);
        return sw.ToString ();
    }
开发者ID:nbogie,项目名称:pachubexml-unity-csharp,代码行数:36,代码来源:EnvironmentXMLWriter.cs

示例12: MergeXMLs

    public void MergeXMLs(string source, string dest)
    {
        System.IO.StreamReader reader = new System.IO.StreamReader(source);
        string xmldata = reader.ReadToEnd();
        reader.Close();
        XmlDocument doc_source = new XmlDocument();
        doc_source.LoadXml(xmldata);

        reader = new System.IO.StreamReader(dest);
        xmldata = reader.ReadToEnd();
        reader.Close();
        XmlDocument doc_dest = new XmlDocument();
        doc_dest.LoadXml(xmldata);

        foreach (XmlNode childs in doc_source.DocumentElement.ChildNodes)
        {
            XmlNode imported = doc_dest.ImportNode(childs, true);
            if (getNodeAsChild(imported, doc_dest.DocumentElement) == null)
                doc_dest.DocumentElement.AppendChild(imported);
        }

        XmlTextWriter	writer = new XmlTextWriter(dest, System.Text.Encoding.UTF8);
        writer.Indentation = 4;
        writer.Formatting = Formatting.Indented;
        writer.Settings.NewLineHandling = NewLineHandling.Entitize;
        writer.Settings.NewLineOnAttributes = true;
        doc_dest.WriteTo(writer);
        writer.Close();
    }
开发者ID:peyman-abdi,项目名称:unity_agents,代码行数:29,代码来源:ManifestEditor.cs

示例13: NewSnippet

    private static void NewSnippet(string content, string tabTrigger, string description, string fileName)
    {
        XmlDocument doc = new XmlDocument();
        {
            XmlElement rootNode = doc.CreateElement("snippet");
            doc.AppendChild(rootNode);
            {
                XmlElement contentNode = doc.CreateElement("content");
                rootNode.AppendChild(contentNode);
                {
                    XmlCDataSection cdataNode = doc.CreateCDataSection(content);
                    contentNode.AppendChild(cdataNode);
                }

                XmlElement tabTriggerNode = doc.CreateElement("tabTrigger");
                rootNode.AppendChild(tabTriggerNode);
                {
                    XmlText textNode = doc.CreateTextNode(tabTrigger);
                    tabTriggerNode.AppendChild(textNode);
                }

                XmlElement scopeNode = doc.CreateElement("scope");
                rootNode.AppendChild(scopeNode);
                {
                    XmlText textNode = doc.CreateTextNode("source.lua");
                    scopeNode.AppendChild(textNode);
                }

                XmlElement descriptionNode = doc.CreateElement("description");
                rootNode.AppendChild(descriptionNode);
                {
                    XmlText textNode = doc.CreateTextNode(description);
                    descriptionNode.AppendChild(textNode);
                }
            }
        }

        StringBuilder sb = new StringBuilder();
        StringWriter sw = new StringWriter(sb);
        XmlTextWriter xtw = null;
        try
        {
            xtw = new XmlTextWriter(sw);
            xtw.Formatting = Formatting.Indented;
            xtw.Indentation = 1;
            xtw.IndentChar = '\t';
            doc.WriteTo(xtw);
        }
        catch(Exception e)
        {
            throw e;
        }
        finally
        {
            if(xtw != null)
            {
                xtw.Close();
                xtw = null;
            }
        }

        File.WriteAllText(saveToFolder + "/" + fileName + ".sublime-snippet", sb.ToString());
    }
开发者ID:moto2002,项目名称:unityLab,代码行数:63,代码来源:LuaSublimeSnippet.cs

示例14: ParseRoomTemplates

    private static bool ParseRoomTemplates(RoomTemplateManager roomTemplateManager)
    {
        bool success = true;
        string template_path = roomTemplateManager.mapTemplatePath;
        string[] templateFiles = null;
        List<CompressedRoomTemplate> compressedRoomTemplates = new List<CompressedRoomTemplate>();

        try
        {
            templateFiles = Directory.GetFiles(template_path, "*.oel");

        }
        catch (System.Exception ex)
        {
            Debug.LogError("RoomTemplateParser: ERROR: Invalid template folder directory: "+template_path);
            Debug.LogException(ex);
            success = false;
        }

        if (success)
        {
            if (templateFiles != null && templateFiles.Length > 0)
            {
                foreach (string templateFile in templateFiles)
                {
                    string templateName = Path.GetFileNameWithoutExtension(templateFile);

                    try
                    {
                        RoomTemplate roomTemplate = null;
                        byte[] compressedNavCells = null;
                        byte[] compressedPVS = null;

                        // Parse the XML template from the file
                        XmlDocument doc = new XmlDocument();
                        doc.Load(templateFile);

                        try
                        {
                            // Parse the room template xml into a room template object
                            roomTemplate = RoomTemplate.ParseXML(templateName, doc);

                            // Extract the nav-mesh and visibility data in compressed form to save into the DB
                            roomTemplate.NavMeshTemplate.ToCompressedData(out compressedNavCells, out compressedPVS);

                            // Remove everything from the template XML that we wont care about at runtime
                            RemoveXmlNodeByXPath(doc, "/level/NavMesh");
                            RemoveXmlNodeByXPath(doc, "/level/Entities");
                        }
                        catch (System.Exception ex)
                        {
                            Debug.LogError("RoomTemplateParser: ERROR: Problem(s) parsing room template:"+templateFile);
                            Debug.LogException(ex);
                            roomTemplate = null;
                            success = false;
                        }

                        if (roomTemplate != null &&
                            ValidateRoomTemplate(
                                templateName,
                                roomTemplate,
                                compressedNavCells,
                                compressedPVS))
                        {
                            // Save the XML back into string
                            StringWriter stringWriter = new StringWriter();
                            XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
                            doc.WriteTo(xmlWriter);

                            compressedRoomTemplates.Add(
                                new CompressedRoomTemplate
                                {
                                    templateName = templateName,
                                    xml = stringWriter.ToString(),
                                    compressedNavCells = compressedNavCells,
                                    compressedVisibility = compressedPVS
                                });

                            Debug.Log("RoomTemplateParser: Added Room Template: " + templateName);
                        }
                        else
                        {
                            Debug.LogError("RoomTemplateParser: ERROR: Problem(s) validating room template: "+templateFile);
                            success = false;
                        }
                    }
                    catch (XmlException ex)
                    {
                        Debug.LogError("RoomTemplateParser: ERROR: Unable to parse XML: " + templateFile);
                        Debug.LogException(ex);
                        success = false;
                    }
                    catch (Exception ex)
                    {
                        Debug.LogError("RoomTemplateParser: ERROR: Unknown error parsing template file: "+templateFile);
                        Debug.LogException(ex);
                        success = false;
                    }
                }
            }
//.........这里部分代码省略.........
开发者ID:ltloibrights,项目名称:AsyncRPG,代码行数:101,代码来源:RoomTemplateImporter.cs

示例15: UpdateOrCreateAppSetting

 /// <summary>
 /// 更新或新增[appSettings]节点的子节点值,存在则更新子节点Value,不存在则新增子节点,返回成功与否布尔值
 /// </summary>
 /// <param name="configurationFile">要操作的配置文件名称,枚举常量</param>
 /// <param name="key">子节点Key值</param>
 /// <param name="value">子节点value值</param>
 /// <returns>返回成功与否布尔值</returns>
 public static bool UpdateOrCreateAppSetting(ConfigurationFile configurationFile, string key, string value)
 {
     bool isSuccess = false;
     string filename = string.Empty;
     if (configurationFile.ToString() == ConfigurationFile.AppConfig.ToString())
     {
         filename = System.Windows.Forms.Application.ExecutablePath + ".config";
     }
     else
     {
         filename = System.AppDomain.CurrentDomain.BaseDirectory + "web.config";
     }
     XmlDocument doc = new XmlDocument();
     doc.Load(filename); //加载配置文件
     XmlNode node = doc.SelectSingleNode("//appSettings");   //得到[appSettings]节点
     try
     {
         ////得到[appSettings]节点中关于Key的子节点
         XmlElement element = (XmlElement)node.SelectSingleNode("//add[@key='" + key + "']");
         if (element != null)
         {
             //存在则更新子节点Value
             element.SetAttribute("value", value);
         }
         else
         {
             //不存在则新增子节点
             XmlElement subElement = doc.CreateElement("add");
             subElement.SetAttribute("key", key);
             subElement.SetAttribute("value", value);
             node.AppendChild(subElement);
         }
         //保存至配置文件(方式一)
         using (XmlTextWriter xmlwriter = new XmlTextWriter(filename, null))
         {
             xmlwriter.Formatting = Formatting.Indented;
             doc.WriteTo(xmlwriter);
             xmlwriter.Flush();
         }
         isSuccess = true;
     }
     catch (Exception ex)
     {
         isSuccess = false;
         throw ex;
     }
     return isSuccess;
 }
开发者ID:hj-nicholas,项目名称:BaseFrame,代码行数:55,代码来源:ConfigHelper.cs


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