zoukankan      html  css  js  c++  java
  • 读取文件夹下所有文件名,饼写入xml

     DirectoryInfo dinfo = new DirectoryInfo(Server.MapPath("~/etao/item/"));
            FileInfo[] files = dinfo.GetFiles("*.xml");  //读取item文件夹下所有文件名
    
            FileInfo file = new FileInfo(Server.MapPath("~/etao/FullIndex.xml"));
            XmlTextWriter textWriter = new XmlTextWriter(Server.MapPath("~/etao/FullIndex.xml"), Encoding.UTF8);
            textWriter.WriteStartDocument();
            textWriter.WriteStartElement("root");
    
            textWriter.WriteElementString("version", "1.0");
            textWriter.WriteElementString("modified", DateTime.Now.ToString());
            textWriter.WriteElementString("seller_id", "官网");
            textWriter.WriteElementString("cat_url", config.PayUrl + "etao/SellerCats.xml");
            textWriter.WriteElementString("dir", config.PayUrl + "etao/item/");
            textWriter.WriteStartElement("item_ids");
    
            foreach (System.IO.FileInfo fi in files)
            {
                textWriter.WriteStartElement("outer_id");
                textWriter.WriteStartAttribute("action");
                textWriter.WriteString("upload");
                textWriter.WriteEndAttribute();
                textWriter.WriteString(fi.Name.Replace(".xml",""));
                textWriter.WriteEndElement();
            }
    
            textWriter.WriteEndElement();
    
            textWriter.WriteEndDocument();
            textWriter.Close();
    

    写入xml后:
     <?xml version="1.0" encoding="utf-8" ?> 
    - <root>
      <version>1.0</version> 
      <modified>2011-7-11 15:25:46</modified> 
      <seller_id>官网</seller_id> 
      <cat_url>http:///etao/SellerCats.xml</cat_url> 
      <dir>http:///etao/item/</dir> 
    - <item_ids>
      <outer_id action="upload">ID1000018289</outer_id> 
      <outer_id action="upload">ID1000018292</outer_id> 
      <outer_id action="upload">ID1000018294</outer_id> 
      <outer_id action="upload">ID1000018298</outer_id> 
      <outer_id action="upload">ID1000018299</outer_id> 
      <outer_id action="upload">ID1000018303</outer_id> 
      <outer_id action="upload">ID1000018305</outer_id> 
      <outer_id action="upload">ID1000018309</outer_id> 
      <outer_id action="upload">ID1000018412</outer_id> 
      <outer_id action="upload">ID1000018413</outer_id> 
      <outer_id action="upload">ID1000018452</outer_id> 
      </item_ids>
      </root>
    

  • 相关阅读:
    集合 排序 判断元素相等 [MD]
    软键盘 输入法管理器 InputMethodManager
    VideoView 视频播放 示例
    富文本 Htmll类 html标签
    MediaPlayer+SurfaceView 视频播放 示例
    SoundPool 音频播放 详解 示例
    MediaPlayer 音频播放 示例
    Strategy 策略模式 MD
    Chain of Responsibility 责任链模式 [MD]
    Iterator 迭代器模式 [MD]
  • 原文地址:https://www.cnblogs.com/yhdkzy/p/2103093.html
Copyright © 2011-2022 走看看