XML读写部分代码,仅供参考!

XmlDocument doc = new XmlDocument();
                doc.Load(GetXmlPath(FilePath));
                XmlNodeReader nodereader = new XmlNodeReader(doc);
               // XmlNodeList emelis = doc.SelectNodes("../w:p[text()!='']");
                XmlNodeList emelis = doc.GetElementsByTagName("w:p");
                XmlTextWriter xtw = new XmlTextWriter(XliffPath,System.Text.Encoding.Unicode);
                xtw.WriteStartDocument();


                xtw.WriteStartElement("TRANSLATEFILE");
                xtw.WriteStartElement("INSRUCTION");
                xtw.WriteAttributeString("Path", XliffPath);
                xtw.WriteAttributeString("Creator", "chenjie");   //获取创建人还需要完善
                xtw.WriteAttributeString("Date", System.DateTime.Now.ToShortDateString());
                xtw.WriteEndElement();
                xtw.WriteStartElement("ARTICLE");
              
                for (int i = 0; i < emelis.Count; i++)
                {
                    xtw.WriteStartElement("Para");
                    sentence = emelis[i].InnerText.ToString();
                    int StartPos = 0;
                    while (StartPos < sentence.Length)
                    {
                        if (IsElement == 1)
                        {
                            xtw.WriteStartElement("Tu");
                            xtw.WriteStartElement("Tuv");
                            xtw.WriteAttributeString("Language", "SourceLanguage");
                            IsElement = 0;
                        }
                        xtw.WriteString(sentence.Substring(StartPos, 1));
                        if (sentence[StartPos].ToString() == "." || sentence[StartPos].ToString() == ":" || sentence[StartPos].ToString() == "?" || sentence[StartPos].ToString() == "!" || sentence[StartPos].ToString() == "。" || sentence[StartPos].ToString() == ":" || sentence[StartPos].ToString() == "?" || sentence[StartPos].ToString() == "!")
                        {
                            IsDivideText idt = new IsDivideText();
                            if (IsElement == 0 && idt.IsDivideTag(sentence, StartPos))
                            {
                                xtw.WriteEndElement();
                                xtw.WriteStartElement("Tuv");
                                xtw.WriteAttributeString("Language", "TargetLanguage");
                                xtw.WriteEndElement();
                                xtw.WriteEndElement();
                                IsElement = 1;

                            }
                        }
                        StartPos++;
                    }
                    if (IsElement == 0)
                    {
                        xtw.WriteEndElement();
                        xtw.WriteStartElement("Tuv");
                        xtw.WriteAttributeString("Language", "TargetLanguage");
                        xtw.WriteEndElement();
                        xtw.WriteEndElement();
                        IsElement = 1;

                    }

                    xtw.WriteEndElement();

                }
                xtw.WriteEndElement();
                xtw.WriteEndElement();
                xtw.WriteEndDocument();
                xtw.Flush();
                xtw.Close();
                doc.Save(GetXmlPath(FilePath));
                File.Delete(GetXmlPath(FilePath));
            }
            catch { }

阅读更多
文章标签: xml date path
个人分类: 代码_数据库访问
上一篇解决方案名称和数据表名称规范
下一篇raptier生成后的程序数据库连接
想对作者说点什么? 我来说一句

MFC c#读写XML文件工程

2011年10月11日 139KB 下载

XML的schema部分代码

2008年09月22日 10KB 下载

xml使用教程、例证、代码

2009年09月30日 5.04MB 下载

java读写xml代码

2008年04月10日 4KB 下载

QT中对XML进行读写操作

2010年01月02日 854KB 下载

FPGA SD卡资料

2013年09月30日 4KB 下载

没有更多推荐了,返回首页

关闭
关闭