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

原创 2007年09月18日 09:28:00

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文件工具类封装

为了满足系统的灵活性,有些功能经常需要用到配置文件,一般是xml格式的居多.如何能快速读写配置文件呢?    以前都是用dom4j提供的api来读写xml文件,用dom4j读写配置文件总感觉像是...
  • lk_blog
  • lk_blog
  • 2012年11月24日 21:47
  • 4664

dom4j读写xml文件方法和具体实现代码(提供jar包下载)

dom4j读写xml文件以及dom4j的jar包下载

java读写xml的代码

  • 2008年04月10日 19:54
  • 4KB
  • 下载

JAVA对XML文件的读写(有具体的代码和解析)

XML 指可扩展标记语言(EXtensible Markup Language),是独立于软件和硬件的信息传输工具,应用于 web 开发的许多方面,常用于简化数据的存储和共享。xml指令 处理指令,...

直接读写XML文件 (例子和代码)

  • 2006年01月13日 09:51
  • 238KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:XML读写部分代码,仅供参考!
举报原因:
原因补充:

(最多只允许输入30个字)