2012-12-17 101 views
1

我將遷移Lotus Notes數據庫的內容到SharePoint。整個數據庫被導出到XML文件(這個要求不能改變),我必須解析這些XML文件並將數據插入SharePoint。從Lotus Notes XML富文本元素中提取文本

什麼讓我起來是包含豐富文本的元素。該XML元素包含在http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp?topic=%2Fcom.ibm.designer.domino.main.doc%2FH_PARAGRAPH_DEFINITIONS_ELEMENT_XML.html

描述在使用DXL Lotus Notes中的領域使​​用的確切富文本格式的XML表示我不需要保持文本的實際格式(除非這是因爲同樣容易檢索純文本),但是如果我只是簡單地提取包含富文本的XML元素的值(使用LinqToXML),我就可以得到沒有換行符的純文本,這是不可接受的。此外,嵌入的圖像作爲base64編碼的字符串顯示在檢索到的文本中(它們嵌入在XML中)。

任何人都可以提供有關如何從XML元素中提取文本的指導,既可以將RTF格式插入到RTF文件中,也可以將純文本包含正確的換行符並且不包含嵌入圖像?

回答

0

我(現在)只是剝離使用正則表達式用下面的表達式所有的XML標記和不必要的嵌入式元素的富文本XML元素:

 //Removes all attachmentref elements 
     newString = new Regex(@"(<attachmentref(.|\n)*</attachmentref>)").Replace(newString, ""); 
     //Removes all formula elements 
     newString = new Regex(@"(<formula(.|\n)*</formula>)").Replace(newString, ""); 
     //Removes all xml tags (<par>, <pardef>, <table> etc). Be aware that this also removes any content in the table 
     newString = new Regex("<(.)*/>").Replace(newString, ""); 
     newString = new Regex("<(.)*>").Replace(newString, ""); 
     newString = new Regex("</(.)*>").Replace(newString, ""); 

     //Trims the text to tidy up the many \n, \r and white-spaces introduced by removing the xml tags. 
     newString = new Regex(@"\r").Replace(newString, "\n"); 
     newString = new Regex(@"[ \f\r\t\v]+\n").Replace(newString, "\n"); 
     newString = new Regex(@"\n{2,}").Replace(newString, "\n"); 

     //makes <and> appear correctly in the text. 
     newString = newString.Replace("&lt;", "<").Replace("&gt;", ">"); 

它不漂亮,但至少文本是可讀的,並保留一些換行感。

0

您可以將富文本項目內容轉換爲富文本項目支持格式HTML/MIME。

或者您可以創建一個XPage或表單來顯示HTTP URL中的富文本內容,並在導出XML中引用該內容。

  • PANU
+0

感謝您的建議。可悲的是我無法控制如何創建導出XML或使用哪種格式。 – michn

1

很明顯,您處理的XML是DXL。一個更優雅的方法是使用XSL轉換將其轉換爲HTML。您可能會發現必需的XSLT樣式表,其中包含PD4ML tool。從HTML格式文檔可以轉換爲PDF,RTF或與PD4ML圖像(或可能轉換爲另一種格式使用另一種工具)

+0

@zfr非常好的選擇,但是您需要密切關注Notes的翻譯不正確的項目符號和其他格式。 – Ewen