亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 11288 | 回復: 3
打印 上一主題 下一主題

[新手問題]怎么修改xml文件中某個key的值? [復制鏈接]

論壇徽章:
0
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2011-06-13 11:58 |只看該作者 |倒序瀏覽
比如,.vcproj文件中
  1.                         <Tool
  2.                                 Name="VCCLCompilerTool"
  3.                                 Optimization="0"
  4.                                 AdditionalIncludeDirectories="./include;./src;../../common/include"
  5.                                 PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
  6.                                 MinimalRebuild="true"
  7.                                 BasicRuntimeChecks="3"
  8.                                 RuntimeLibrary="3"
  9.                                 UsePrecompiledHeader="0"
  10.                                 WarningLevel="3"
  11.                                 Detect64BitPortabilityProblems="true"
  12.                                 DebugInformationFormat="4"
  13.                         />
復制代碼
可以用xml.dom.minidom模塊讀取到PreprocessorDefinitions的值。
現(xiàn)在要替換PreprocessorDefinitions中的WIN32為WIN64,并把修改結果寫回xml文件。

這種操作可以用到哪些模塊和方法?新手,對相關的處理模塊不是很熟悉~~ 求教,十分感謝~~

論壇徽章:
0
2 [報告]
發(fā)表于 2011-06-13 14:31 |只看該作者
直接調(diào)用set_text方法,然后寫回去不

論壇徽章:
0
3 [報告]
發(fā)表于 2011-06-13 16:01 |只看該作者
  1.         dom = xml.dom.minidom.parseString(xml_content)
  2.         root = dom.documentElement
  3.         for config_element in root.getElementsByTagName("Configuration"):
  4.                 if config_element.getAttribute("Name") == config_tag:
  5.                         for tool_element in config_element.getElementsByTagName("Tool"):
  6.                                 if tool_element.getAttribute("Name") == "VCCLCompilerTool":
  7.                                         item_value = tool_element.getAttribute("PreprocessorDefinitions")
  8.                                         if len(item_value) > 0:
  9.                                                 #print "%s:%s" %(config_tag, item_value)
  10.                                                 tool_element.setAttribute("PreprocessorDefinitions", new_macro)
  11.                                                 item_value = tool_element.getAttribute("PreprocessorDefinitions")
  12.                                                 #print "%s:%s" %(config_tag, item_value)
  13.                                                 #print xml_content        # debug only
  14.                                                 return item_value
復制代碼
setAttribute()方法修改后,在下一次調(diào)用getAttribute()能得到修改后的值~~ 但是print xml_content時這個修改后的值并未出現(xiàn)~~ 修改后的值若能出現(xiàn)在xml_content中,則可以重新寫文件即可得到修改后的.vcproj

怎么把修改后的值也在xml_content中修改???

論壇徽章:
0
4 [報告]
發(fā)表于 2011-06-14 10:49 |只看該作者
setAttribute()修改之后的內(nèi)容可通過調(diào)用root.toxml()得到~~

print root.toxml() 或是把這個輸出寫入文件~~


嚯嚯~~ 結貼~~
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP