Ios 在swift中从xml读取注释或注释节点 首先,考虑如下的XML结构: <!-- this is a comment --> <methods> <include name="test" /> <include name="test" /> <!-- <include name="testcase-commented" />--> <!-- <include name="testcase-commented" />--> <!-- <include name="testcase-commented" />--> <include name="test" /> </methods>

Ios 在swift中从xml读取注释或注释节点 首先,考虑如下的XML结构: <!-- this is a comment --> <methods> <include name="test" /> <include name="test" /> <!-- <include name="testcase-commented" />--> <!-- <include name="testcase-commented" />--> <!-- <include name="testcase-commented" />--> <include name="test" /> </methods>,ios,swift,macos,swift2,osx-elcapitan,Ios,Swift,Macos,Swift2,Osx Elcapitan,但是,没有使用此方法解析已注释的测试用例 是否有任何方法可以使用xml解析器从xml中仅读取已注释的testcase名称,或者无法在swift中从xml中读取已注释的标记 没有通过网络找到解决方案 我正在使用 xcode 7.3 OSX 10.11 and swift 2.2 首先,我要感谢AlexanderMomchliov的伟大建议,我希望您知道如何解析xml文件 解析器有一些重载方法,从这里开始,只需调用: func parser(parser: NSXMLParser, foundCo

但是,没有使用此方法解析已注释的测试用例

是否有任何方法可以使用xml解析器从xml中仅读取已注释的testcase名称,或者无法在swift中从xml中读取已注释的标记

没有通过网络找到解决方案

我正在使用

xcode 7.3 OSX 10.11 and swift 2.2

首先,我要感谢AlexanderMomchliov的伟大建议,我希望您知道如何解析xml文件

解析器有一些重载方法,从这里开始,只需调用:

func parser(parser: NSXMLParser, foundComment comment: String) {

    print(comment)
}
如果xml文件为,则有一些注释节点,如:

<!-- this is a comment -->
<test name="testOne">
<classes>
    <class name="TestClassOne">
        <methods>
            <include name="test_480" />
<!--                <include name="test_481" />-->
<!--                <include name="test_482" />-->
        </methods>
    </class>
</classes>
</test>

然后,输出将如下所示:

this is a comment
<include name="test_481" />
<include name="test_482" />
这是一条评论
您可以覆盖
NSXMLParserDelegate
中的方法,以便在找到注释时收到通知

func parser(parser: NSXMLParser, foundComment comment: String) {
    print(comment)
}

注释的全部目的是能够输入没有语义意义的数据。你为什么要解析它们?@AlexanderMomchliov谢谢你的关注,是的,我知道我可以存储在一个没有语义意义的文件中。但我的要求是这样的。。。。您必须知道已注释的测试用例名称。那么您可能需要自己,因为您需要的基本上不再是XML。您可能需要编写自己的解析器。同样,我建议将设计更改为不需要这样做。也许不要注释掉测试用例,而是给它们一个属性,比如
ignore=“true”
。使用支持regex find/replace的文本编辑器,将
替换为
$1ignore=“true”$2
,然后boom,所有注释都转换为属性化的非注释。
func parser(parser: NSXMLParser, foundComment comment: String) {
    print(comment)
}