2014-06-10 48 views
0

我正在尋找將包含用戶文本輸入的字符串添加到筆記的note.content中。閱讀後,我發現如何添加資源,但我不希望資源成爲附件,我希望它成爲實際的文本。將字符串連接到Python中的印象筆記標記語言(ENML)

下面是一些代碼:

title= self.textEditTitle.text() 
    body= self.textEditBody.text()   

    auth_token = "secret stuff!" 

    client = EvernoteClient(token=auth_token, sandbox=True) 

    note_store = client.get_note_store() 

    nBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" 
    nBody += "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">" 
    nBody += "<en-note>%s</en-note>" % body 

    note = Types.Note() 
    note.title = title 
    note.content= nBody 

任何意見將是巨大的,因爲我剛剛開始使用這個API,它看起來就像是充滿潛力,一旦我看着辦吧!這裏是我一直主要閱讀:http://dev.evernote.com/documentation/cloud/chapters/ENML.php

回答

0

找到了答案。首先,我使用的是QString對象,而不是普通的字符串對象。我將QString作爲一個字符串進行鑄造,並將內容分開,以便我將自己的主體變量連接起來。我也將這個字符串編碼到xmlcharrefreplace中,但我仍然在讀這個。儘管如此,它的工作。這裏是代碼剪輯:

body= str(self.textEditBody.text()) 
    auth_token = "secret!" 
    client = EvernoteClient(token=auth_token, sandbox=True) 
    note_store = client.get_note_store() 

    nBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" 
    nBody += "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">" 
    nBody += "<en-note>" 
    nBody += body.encode('ascii', 'xmlcharrefreplace') 
    nBody += "</en-note>"