我有一些python代码用xml.dom.minidom生成一些XML文本.现在,我从终端运行它,结果输出一个结构化的XML.我还想生成一个XML文件并将其保存到我的磁盘.怎么可能这样呢?
这就是我所拥有的:
import xml
from xml.dom.minidom import Document
import copy
class dict2xml(object):
doc = Document()
def __init__(self, structure):
if len(structure) == 1:
rootName = str(structure.keys()[0])
self.root = self.doc.createElement(rootName)
self.doc.appendChild(self.root)
self.build(self.root, structure[rootName])
def build(self, father, structure):
if type(structure) == dict:
for k in structure:
tag = self.doc.createElement(k)
father.appendChild(tag)
self.build(tag, structure[k])
elif type(structure) == list:
grandFather = father.parentNode
tagName = father.tagName
# grandFather.removeChild(father)
for l in structure:
tag = self.doc.createElement(tagName.rstrip('s'))
self.build(tag, l)
father.appendChild(tag)
else:
data = str(structure)
tag = self.doc.createTextNode(data)
father.appendChild(tag)
def …
Run Code Online (Sandbox Code Playgroud) 我有NSString
这样的
NSString *string = @"textTextTextTextText<br>textTextTextText<br>TextTextText"
我想将此设置NSString
为我的文本,在字符串UICell
上
找到的每个标记上都有一个新行.我怎么能这样做?
我试过这个,没有成功:
cell.textLabel.text = [[text componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@"<br>"];
我有一个 ObjC 项目,并且在 Swift 中添加了一个 WatchApp 扩展目标。它工作正常,但是我有一个数据库处理程序类,我想让它从 watch 扩展目标访问,以便从中获取一些数据。我已经在扩展目标的桥接头文件中添加了数据库类,但是当我在应用程序 viewController 中实例化该类时,我收到一个缺少符号的错误。我正在尝试在 Header Search Path 中添加类的路径,但它仍然不起作用。有没有人知道我错过了什么?