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


C# XmlDocument.CreateElement方法代码示例

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


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

示例1: SaveStatistik

    public void SaveStatistik(string statText, string name)
    {
        CheckFile ();
        // Создаем корневой элемент
        XmlDocument xmlDoc = new XmlDocument ();
        if(File.Exists(filePatch))
            xmlDoc.Load (filePatch);

        XmlNode xRoot;
        XmlNode findNode = xmlDoc.SelectSingleNode ("Stats"); // найти корневой элемент
        if ( findNode == null)
            xRoot = xmlDoc.CreateElement ("Stats"); 	// Создать корневой элемент
        else
            xRoot = findNode;

        xmlDoc.AppendChild (xRoot);

        //Временные преременные для дочерних элементов и атрибутов
        XmlElement taskElement1; //Элемент 1-го уровня

        findNode = xmlDoc.SelectSingleNode ("Stats/" + name);
        if ( findNode == null) {
            taskElement1 = xmlDoc.CreateElement (name);
            taskElement1.InnerText = statText;
            xRoot.AppendChild (taskElement1);
        } else {
            findNode.InnerText = statText;
        }

        /////////////////////////////////////////////////////////////
        xmlDoc.Save ("Data/Save/Stats.xml");
    }
开发者ID:Antis28,项目名称:JuperFly,代码行数:32,代码来源:SaveStats.cs

示例2: Main

 public static void Main()
 {
     String connect = "Provider=Microsoft.JET.OLEDB.4.0;"
       + @"data source=c:\booksharp\gittleman\ch15\Sales.mdb";
     OleDbConnection con = new OleDbConnection(connect);
     con.Open();
     Console.WriteLine
       ("Made the connection to the Sales database");
     OleDbCommand cmd = con.CreateCommand();
     cmd.CommandText = "SELECT * FROM Customer";
     OleDbDataReader reader = cmd.ExecuteReader();
     XmlDocument document = new XmlDocument();
     XmlElement customers = document.CreateElement("customers");
     document.AppendChild(customers);
     while (reader.Read()) {
       XmlElement customer = document.CreateElement("customer");
       customers.AppendChild(customer);
       XmlElement name = document.CreateElement("name");
       customer.AppendChild(name);
       name.AppendChild
        (document.CreateTextNode(reader.GetString(1)));
       XmlElement address = document.CreateElement("address");
       customer.AppendChild(address);
       address.AppendChild
        (document.CreateTextNode(reader.GetString(2)));
       XmlElement balance = document.CreateElement("balance");
       customer.AppendChild(balance);
       Decimal b = reader.GetDecimal(3);
       balance.AppendChild
                   (document.CreateTextNode(b.ToString()));
     }
     document.Save(Console.Out);
     reader.Close();
 }
开发者ID:JnS-Software-LLC,项目名称:CSC153,代码行数:34,代码来源:MakeXml.cs

示例3: Config

 /// <summary>
 /// Creates a new instance of config provider
 /// </summary>
 /// <param name="configType">Config type</param>
 protected Config(Type configType)
 {
     if (configType == null)
     {
         throw new ArgumentNullException("configType");
     }
     _document = new XmlDocument();
     if (File.Exists(ConfigFile))
     {
         _document.Load(ConfigFile);
     }
     else
     {
         var declaration = _document.CreateXmlDeclaration("1.0", "UTF-8", null);
         _document.AppendChild(declaration);
         var documentNode = _document.CreateElement(CONFIG_NODE);
         _document.AppendChild(documentNode);
     }
     _typeNode = _document.DocumentElement.SelectSingleNode(configType.Name);
     if (_typeNode == null)
     {
         _typeNode = _document.CreateElement(configType.Name);
         _document.DocumentElement.AppendChild(_typeNode);
     }
 }
开发者ID:san90279,项目名称:UK_OAS,代码行数:29,代码来源:Config.cs

示例4: GetXml

    /// <summary>
    /// To Create Xml file for every multiselect list to pass data of xml type in database
    /// </summary>
    /// <param name="DtXml"></param>
    /// <param name="Text"></param>
    /// <param name="Value"></param>
    /// <param name="XmlFileName"></param>
    /// <returns></returns>
    public string GetXml(DataTable DtXml, String Text, String Value,string XmlFileName)
    {
        XmlDocument xmldoc = new XmlDocument();
        //To create Xml declarartion in xml file
        XmlDeclaration decl = xmldoc.CreateXmlDeclaration("1.0", "UTF-16", "");
        xmldoc.InsertBefore(decl, xmldoc.DocumentElement);
        XmlElement RootNode = xmldoc.CreateElement("Root");
        xmldoc.AppendChild(RootNode);
        for (int i = 0; i < DtXml.Rows.Count; i++)
        {
            XmlElement childNode = xmldoc.CreateElement("Row");
            childNode.SetAttribute(Value, DtXml.Rows[i][1].ToString());
            childNode.SetAttribute(Text, DtXml.Rows[i][0].ToString());
            RootNode.AppendChild(childNode);
        }

        //Check if directory already exist or not otherwise
        //create directory
        if (!Directory.Exists(System.Web.HttpContext.Current.Server.MapPath("XML")))
            Directory.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath("XML"));
        XmlFileName = "XML" + "\\" + XmlFileName;

        //To save xml file on respective path
        xmldoc.Save(System.Web.HttpContext.Current.Server.MapPath(XmlFileName));
        xmldoc.RemoveChild(xmldoc.FirstChild);
        string RetXml = xmldoc.InnerXml;
        return RetXml;
    }
开发者ID:kamleshdaxini,项目名称:LocalDevelopment,代码行数:36,代码来源:DynamicXml.cs

示例5: SaveDataForCurrentUser

    public static void SaveDataForCurrentUser()
    {
        try
        {
            string currentUser = TransitionData.GetUsername();

            _document = new XmlDocument();

            XmlElement completedLevels = _document.CreateElement(COMPLETED_LEVELS_NODE_NAME);

            foreach (string answer in _completedLevels)
            {
                XmlElement completedLevelNode = _document.CreateElement(answer);

                completedLevels.AppendChild(completedLevelNode);
            }

            _document.AppendChild(completedLevels);

            _document.Save(GetSaveDataPathForUser(currentUser));
        }
        catch(Exception e)
        {
            Debug.LogError(e);
        }
    }
开发者ID:ednedfed,项目名称:WordGuess,代码行数:26,代码来源:SaveData.cs

示例6: saveXML

    public void saveXML(string path)
    {
        XmlDocument doc = new XmlDocument ();
        XmlElement main = doc.CreateElement ("Config");
        XmlAttribute version = doc.CreateAttribute ("Version");
        version.Value = configVersion;
        main.Attributes.Append (version);
        XmlAttribute lastMap = doc.CreateAttribute ("lastCompletedMap");
        lastMap.Value = lastCompletedLevel;
        main.Attributes.Append (lastMap);
        XmlNode score = doc.CreateNode (XmlNodeType.Element, "ScoreHistory", "");
        foreach(int i in scoreHistory ){
            XmlElement node = doc.CreateElement("Score");
            XmlAttribute val = doc.CreateAttribute("Value");
            val.Value = i.ToString();
            node.Attributes.Append(val);
            score.AppendChild(node);
        }

        main.AppendChild (score);
        doc.AppendChild (main);
        doc.Save(path);
        /*
        //doc.l
        using (var stream = new FileStream(path, FileMode.Create)) {
            using (StreamWriter writer = new StreamWriter(stream))
                writer.Write (data);
        }
        */
    }
开发者ID:allfa,项目名称:Reborn,代码行数:30,代码来源:config.cs

示例7: Log

    private static void Log(string pInfoType, string pFilepath, string pContent, string pDetail, string pRootName)
    {
        if (!AllowLog) return;

        try
        {
            XmlDocument docXml = new XmlDocument();
            try{
                docXml.Load(pFilepath);
            }
            catch (Exception ex){
                docXml = new XmlDocument();
            }

            XmlElement Goc = docXml.DocumentElement;
            if ((Goc == null))
            {
                Goc = docXml.CreateElement(pRootName);
                docXml.AppendChild(Goc);
            }

            XmlElement The = docXml.CreateElement(pInfoType);
            The.SetAttribute("At", DateTime.Now.ToString("dd\\/MM\\/yyyy HH:mm:ss"));
            The.SetAttribute("Message", pContent);
            The.SetAttribute("Detail", pDetail);

            Goc.AppendChild(The);
            docXml.Save(pFilepath);
        }
        catch (Exception ex)
        {
        }
    }
开发者ID:dexonhud,项目名称:pharmacykimhoang,代码行数:33,代码来源:TLog.cs

示例8: ErrorResponse

    private void ErrorResponse(int errNum, string errText)
    {
        try
        {
            XmlDocument d = new XmlDocument();
            XmlElement root = d.CreateElement("response");
            d.AppendChild(root);
            XmlElement er = d.CreateElement("error");
            root.AppendChild(er);
            er.AppendChild(d.CreateTextNode(errNum.ToString()));
            if (errText != "")
            {
                System.Xml.XmlElement msg = d.CreateElement("message");
                root.AppendChild(msg);
                msg.AppendChild(d.CreateTextNode(errText));
            }

            d.Save(Response.Output);
            Response.End();
        }
        catch (Exception)
        {
            //handle the error.
        }
    }
开发者ID:jaytem,项目名称:minGit,代码行数:25,代码来源:xmlrpc.aspx.cs

示例9: SaveXml

    public void SaveXml()
    {
        string filepath = Application.streamingAssetsPath+"\\Xml\\playerCard.xml";
        XmlDocument xmlDoc = new XmlDocument();
        if(File.Exists (filepath))
        {
            xmlDoc.Load(filepath);

            XmlElement elm_Deck = xmlDoc.DocumentElement;
            elm_Deck.RemoveAll();

            for (int i = 0; i < m_cards.Count; i++) {

                XmlElement element_card = xmlDoc.CreateElement("card");
                XmlElement card_id = xmlDoc.CreateElement("id");
                XmlElement card_type = xmlDoc.CreateElement("type");

                if (m_cards[i].GetComponent<CardUnitBehaviour>()) {
                    card_id.InnerText = (m_cards[i].GetComponent<CardUnitBehaviour>().m_id).ToString();
                    card_type.InnerText = m_cards[i].GetComponent<CardUnitBehaviour>().m_type;
                }
                else if (m_cards[i].GetComponent<CardGroundBehaviour>())
                {
                    card_id.InnerText = (m_cards[i].GetComponent<CardGroundBehaviour>().m_id).ToString();
                    card_type.InnerText = m_cards[i].GetComponent<CardGroundBehaviour>().m_type;
                }
                element_card.AppendChild(card_id);
                element_card.AppendChild(card_type);
                elm_Deck.AppendChild(element_card);
            }
            xmlDoc.Save(filepath);
        }
    }
开发者ID:noctisyounis,项目名称:Playground2015_Project4,代码行数:33,代码来源:deck.cs

示例10: GetSuccessCriteriaInfo

    // 指定された達成基準の情報を返します。
    public XmlNode GetSuccessCriteriaInfo(XmlDocument xml, string id)
    {
        DataRow r = this.Rows.Find(id);

        XmlNode result = xml.CreateDocumentFragment();

            string name = r[NameColumnName].ToString();
            string level = r[LevelColumnName].ToString();

            XmlElement sc = xml.CreateElement("SuccessCriteria");

            XmlElement numberElement = xml.CreateElement("number");
            numberElement.InnerText = id;
            sc.AppendChild(numberElement);

            XmlElement nameElement = xml.CreateElement("name");
            nameElement.InnerText = name;
            sc.AppendChild(nameElement);

            XmlElement levelElement = xml.CreateElement("level");
            levelElement.InnerText = level;
            sc.AppendChild(levelElement);

            result.AppendChild(sc);

        return result;
    }
开发者ID:bakera,项目名称:WAIC-AS-HTML-Generator,代码行数:28,代码来源:SuccessCriteriaTable.cs

示例11: GetAccessToken

    public XmlDocument GetAccessToken(string id)
    {
        XmlDocument xmlDoc = new XmlDocument();
        XmlElement result = xmlDoc.CreateElement("Result");
        XmlElement XmlElmAccessToken = xmlDoc.CreateElement("accessToken");
        XmlElement XmlElmErrorCode = xmlDoc.CreateElement("ErrorCode");

        try
        {
            VerifyID(id);
            string accesstoken = GenerateAccessToken(id);
            XmlElmAccessToken.InnerText = accesstoken;
            result.AppendChild(XmlElmAccessToken);
            xmlDoc.AppendChild(result);
        }
        catch (SSOLogingException ex)
        {
            throw new SoapException(ex.msg, SoapException.ServerFaultCode);
        }
        catch (Exception ex)
        {
            throw new SoapException(ex.Message, SoapException.ServerFaultCode);
        }

        return xmlDoc;
    }
开发者ID:neiltuma,项目名称:steve_prj,代码行数:26,代码来源:SSOLogin.cs

示例12: convert

    // основная функция конвертации
    public void convert(String FilePath, String DocmFileName)
    {
        FilePath = @"d:\1\";
        DocmFileName = "130349";
        string DocmFilePath = System.IO.Path.Combine(FilePath.ToString(), (DocmFileName.ToString() + ".docm"));
        string XmlFilePath = System.IO.Path.Combine(FilePath.ToString(), (DocmFileName.ToString() + ".xml"));
        createXML(XmlFilePath, "");
        XmlDocument document = new XmlDocument();
        document.Load(XmlFilePath);
        XmlNode element = document.CreateElement("info");
        document.DocumentElement.AppendChild(element);

        XmlNode title = document.CreateElement("title");
        title.InnerText = FilePath;
        element.AppendChild(title);

        XmlNode chapter = document.CreateElement("chapter");
        document.DocumentElement.AppendChild(chapter);

        using (WordprocessingDocument doc = WordprocessingDocument.Open(DocmFilePath, true))
        {
            var body = doc.MainDocumentPart.Document.Body;
            foreach (var text in body.Descendants<Text>())
            {
                XmlNode para = document.CreateElement("para");
                para.InnerText = text.Text;
                chapter.AppendChild(para);
            }
        }
        document.Save(XmlFilePath);
    }
开发者ID:KateSenko,项目名称:DocmParser_dll,代码行数:32,代码来源:Parser.cs

示例13: btnLisaa_Click

    protected void btnLisaa_Click(object sender, EventArgs e)
    {
        //create new instance of XmlDocument
        XmlDocument theNews = new XmlDocument();

        //load from file
        theNews.Load(Server.MapPath("~/XML/News.xml"));

        //create nodes
        XmlElement theNewsTag = theNews.CreateElement("news");
        XmlElement theTitleTag = theNews.CreateElement("title");
        XmlElement theContentsTag = theNews.CreateElement("contents");
        XmlElement theDateTag = theNews.CreateElement("date");

        //create what data nodes have
        XmlText theTitleText = theNews.CreateTextNode(txtTitle.Text);
        XmlText theContentsText = theNews.CreateTextNode(txtContents.Text);
        XmlText theDateText = theNews.CreateTextNode(System.DateTime.Now.ToString("r"));

        //append them

        theTitleTag.AppendChild(theTitleText);
        theContentsTag.AppendChild(theContentsText);
        theDateTag.AppendChild(theDateText);

        theNewsTag.AppendChild(theTitleTag);
        theNewsTag.AppendChild(theContentsTag);
        theNewsTag.AppendChild(theDateTag);

        //put all under the News tag
        theNews.DocumentElement.PrependChild(theNewsTag);

        // save the file
        theNews.Save(Server.MapPath("~/XML/News.xml"));
    }
开发者ID:elgrim,项目名称:teamslackersrepo,代码行数:35,代码来源:Default.aspx.cs

示例14: createXml

    public void createXml()
    {
        string filepath = Application.dataPath + @"/my.xml";
        if(!File.Exists (filepath))
        {
             XmlDocument xmlDoc = new XmlDocument();
             XmlElement root = xmlDoc.CreateElement("transforms");
             XmlElement elmNew = xmlDoc.CreateElement("rotation");
             elmNew.SetAttribute("id","0");
         		     elmNew.SetAttribute("name","momo");

             XmlElement rotation_X = xmlDoc.CreateElement("x");
             rotation_X.InnerText = "0";
             XmlElement rotation_Y = xmlDoc.CreateElement("y");
             rotation_Y.InnerText = "1";
             XmlElement rotation_Z = xmlDoc.CreateElement("z");
             rotation_Z.InnerText = "2";
           			 rotation_Z.SetAttribute("id","1");

             elmNew.AppendChild(rotation_X);
             elmNew.AppendChild(rotation_Y);
             elmNew.AppendChild(rotation_Z);
             root.AppendChild(elmNew);
             xmlDoc.AppendChild(root);
             xmlDoc.Save(filepath);
             Debug.Log("createXml OK!");
        }
    }
开发者ID:CzDreamer,项目名称:QFramework,代码行数:28,代码来源:Test.cs

示例15: addData

    public void addData(string XmlFilePath, StringBuilder str)
    {
        XmlDocument document = new XmlDocument();

        document.Load(XmlFilePath);
        XmlNode element = document.CreateElement("info");
        document.DocumentElement.AppendChild(element);

        XmlNode title = document.CreateElement("title");
        title.InnerText = XmlFilePath;
        element.AppendChild(title);

        XmlNode chapter = document.CreateElement("chapter");
        document.DocumentElement.AppendChild(chapter); // указываем родителя

        XmlNode para = document.CreateElement("para");
        para.InnerText = str.ToString();
        chapter.AppendChild(para);

        document.Save(XmlFilePath);

        // Console.WriteLine("Data have been added to xml!");

        // Console.ReadKey();
        // Console.WriteLine(XmlToJSON(document));
    }
开发者ID:KateSenko,项目名称:DocmParser_dll,代码行数:26,代码来源:Parser.cs


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