編輯。兩次頭痛之前,我仍然充滿希望。現在我認爲將文件重新格式化以避免像同一行中的元素這樣的奇怪事情並且執行一些空白字符清理會更好。但這很奇怪。什麼錯誤。
嗯,這很奇怪,但我仍然在寫一個答案。
我正在做一些測試,使用一個示例XML和一些從NSXML獲得的行/列號。
<?xml version="1.0"?>
<catalog class="something">
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
...
在
column, line
OPEN/CLOS element
等形式的日誌(我在智能調試漂亮的小白)
15, 2 (A)
OPEN catalog
12, 3 (B)
OPEN book
14, 4
OPEN author
CLOS author
13, 5
OPEN title
CLOS title
13, 6
OPEN genre
CLOS genre
13, 7
OPEN price
CLOS price
20, 8
OPEN publish_date
CLOS publish_date
19, 9
OPEN description
CLOS description
CLOS book
...
有一種永遠奏效一個公式,即:
columnPosition = columnNumber - length("<element>")
例如,考慮第二行和日誌附近(A):
<catalog class="something">
我希望columnPosition
等於0
,其實:
len("<catalog class>") = 15
0 = 15 - length("<catalog class>")
注意NSXML的columnNumber
仍然是15
不管我在「class」標籤內部寫入,但是當我移除整個標籤時,它是9
。用下面的一行:
<catalog>
我希望columnPosition
等於0
,其實:
length("<catalog>") = 9
0 = 9 - length("<catalog>")
現在,考慮下面一行,在日誌(B):
<book id="bk101">
我期待columnNumber
等於3
。其實:
length("<book id>") = 9
3 = 12 - length("<book id>")
好吧,這很奇怪。我認爲這不是一個很好的解決方案,但至少它是有效的。我不能簡單地刪除字符串的開頭空格,因爲它沒有,如果有這樣一行:
<catalog class="something"><book id="bk101">
你覺得這個怎麼樣?我覺得挺有意思的,但是如果沒有別的辦法,我會檢查這個答案作爲接受的答案。我期待着你們的想法。
避免了簡潔和缺乏意志的正式證明。
我在蘋果bug記者提交了一個錯誤,這似乎並不像預期的行爲。 – Donovan