2014-04-24 89 views
0

我必須創建一個宏來更改給定xml中的某些標記並將其保存。 但保存之後,所有轉義字符都會更改,被刪除修改一個xml文件並保存後,將"更改爲「

初始文件:

<?xml version="1.0"?> 
<?mso-application progid="Excel.Sheet"?> 
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" 
xmlns:o="urn:schemas-microsoft-com:office:office" 
xmlns:x="urn:schemas-microsoft-com:office:excel" 
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" 
xmlns:html="http://www.w3.org/TR/REC-html40"> 

...

<DataValidation xmlns="urn:schemas-microsoft-com:office:excel"> 
    <Range>R1C26</Range> 
    <Type>List</Type> 
    <CellRangeList/> 
    <Value>&quot;Credit Limit&quot;</Value> 
    <ErrorMessage>The header row should not be changed.</ErrorMessage> 
    <ErrorTitle>Header Row</ErrorTitle> 
</DataValidation> 

保存後:

<?xml version="1.0"?> 
<?mso-application progid="Excel.Sheet"?> 
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"> 

...

<DataValidation xmlns="urn:schemas-microsoft-com:office:excel"> 
    <Range>R1C26</Range> 
    <Type>List</Type> 
    <CellRangeList/> 
    <Value>"Credit Limit"</Value> 
    <ErrorMessage>The header row should not be changed.</ErrorMessage> 
    <ErrorTitle>Header Row</ErrorTitle> 
</DataValidation> 

我的代碼是這樣的:

Dim xmlDoc As New MSXML2.DOMDocument60 
xmlFile = outputFolder & "\" & f 
xmlDoc.Load xmlFile 
'Make changes here 
xmlDoc.Save xmlFile 

你能幫助我理清了這一點?對不起 -

+0

我需要發送完全相同的XML,我只是改變一些被翻譯的單詞。 – Marisa

+0

沒有確切的XML。任何有效的XML使用者都將接受XML。 –

+0

謝謝。你知道是否有任何文件比較工具允許我跳過CRLF?因爲我需要比較原始文件和修改後的文件,這種格式的變化使得它很難做到。提前致謝。 – Marisa

回答

-1

你「進行更改腳本

面對C#中使用可能HttpServerUtility.HtmlEncode。

對於VBA,你很可能是這樣的:

Function UrlEncode(strString) 'As String 
Dim strUrlEncode 
Dim lngPos 

For lngPos = 1 To Len(strString) 
strUrlEncode = strUrlEncode & "%" & Right("0" & Hex(Asc(Mid(strString, lngPos, 1))), 2) 
Next 
UrlEncode = strUrlEncode 

End Function 

編號:http://vbact.blogspot.com/2010/01/url-encode-in-vba.html

0

最後,我會爲用戶提供工具比較原始和最終的XML文件。例如,XML記事本或Altova DiffDog,所以他們只能看到文件之間的差異,而不是中斷。

相關問題