小编Luc*_*ira的帖子

如何使用python将XML文件保存到磁盘?

我有一些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)

python xml file

10
推荐指数
2
解决办法
4万
查看次数

用新行替换NSString中的<br>

我有NSString这样的

NSString *string = @"textTextTextTextText<br>textTextTextText<br>TextTextText"

我想将此设置NSString为我的文本,在字符串UICell
找到的每个标记上都有一个新行.我怎么能这样做?

我试过这个,没有成功:

cell.textLabel.text = [[text componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@"<br>"];

line-breaks nsstring ios

3
推荐指数
1
解决办法
7966
查看次数

从扩展目标访问主 App 类 - iOS

我有一个 ObjC 项目,并且在 Swift 中添加了一个 WatchApp 扩展目标。它工作正常,但是我有一个数据库处理程序类,我想让它从 watch 扩展目标访问,以便从中获取一些数据。我已经在扩展目标的桥接头文件中添加了数据库类,但是当我在应用程序 viewController 中实例化该类时,我收到一个缺少符号的错误。我正在尝试在 Header Search Path 中添加类的路径,但它仍然不起作用。有没有人知道我错过了什么?

ios swift watchkit ios-extensions

3
推荐指数
1
解决办法
3138
查看次数

标签 统计

ios ×2

file ×1

ios-extensions ×1

line-breaks ×1

nsstring ×1

python ×1

swift ×1

watchkit ×1

xml ×1