2014-04-24 86 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,所以他们只能看到文件之间的差异,而不是中断。

相关问题