带特殊字符的文本分隔符

2024-06-07 10:18:58 发布

您现在位置:Python中文网/ 问答频道 /正文

你好,我在用python编写XML文件时遇到了问题

要写入文件的文本:

<!-- @(#) $Id: ./etc/rules/apache_rules.xml, 2011/09/08 dcid Exp $

  -  Official Apache rules for OSSEC.
  -
  -  Copyright (C) 2009 Trend Micro Inc.
  -  All rights reserved.
  -
  -  This program is a free software; you can redistribute it
  -  and/or modify it under the terms of the GNU General Public
  -  License (version 2) as published by the FSF - Free Software
  -  Foundation.
-->

 <rule id="30100" level="0">
    <decoded_as>apache-errorlog</decoded_as>
    <description>Apache messages grouped.</description>
  </rule>   

但是辛波尔;在comment中,打断字符串并在我的文件中

<!-- @(#) $Id: ./etc/rules/apache_rules.xml, 2011/09/08 dcid Exp $

  -  Official Apache rules for OSSEC.
  -
  -  Copyright (C) 2009 Trend Micro Inc.
  -  All rights reserved.
  -
  -  This program is a free software

没有;写所有的,我可以取代,但另一个可以崩溃的文字再次??为什么

PS:im写入文件

f = open("/tmp/l.xml",'w')
f.write(data["contentXML"])

Tags: 文件theidforapacheasetcxml

热门问题