-1
想要将原始字符串“& quot”写入属性的值。想要将字符串“"”写入xml文件
使用python minidom!
将“& quot”写入XML文件后,它看起来像文件中的“& ampquot”。
请帮我在这....
想要将原始字符串“& quot”写入属性的值。想要将字符串“"”写入xml文件
使用python minidom!
将“& quot”写入XML文件后,它看起来像文件中的“& ampquot”。
请帮我在这....
使用常规双引号中的属性的字符串值。该代码将负责将其转换为XML输出中的"
。
下面是一个例子。首先,创建文档:
In [52]: from xml.dom.minidom import getDOMImplementation
In [53]: impl = getDOMImplementation()
In [54]: doc = impl.createDocument(None, "tag", None)
In [55]: top_element = doc.documentElement
设置顶级元素的“foo”的属性。请注意,字符串中有双引号,它们是“foo”属性的值。
In [56]: top_element.setAttribute("foo", '"plate of shrimp"')
当打印文档时,这些双引号转换为"
:
In [57]: print(top_element.toprettyxml())
<tag foo=""plate of shrimp""/>
的[?我如何逃脱XML&符号(可能的复制http://stackoverflow.com/questions/1328538 /我怎么办 - 我逃跑 - &符 - 在 - xml) –
我刚刚创建了一个答案,但现在我有一个问题。你真的想要'',还是你真的想'"'(这是双引号字符在XML字符串中编码的方式)。如果你真的想要'',那么''&''''实际上应该如何出现在文件中,因为'&'代表和号字符。 –