[已解决] XML文件中的Base64值 [英] [Solved] Base64 Values in an XML File
问题描述
我正在解析XML文件,其值可能会或可能不会经过Base64编码.
我正在使用XmlReader
读取XML文件,然后将其写回到输出文件中(在弄弄了某些元素的值之后).
如果输入文件是Base64编码的,则输出文件也需要同样.
我
a)首先要知道这些值是否是Base64编码的吗?
如果是的话...
我
b)在使用XmlReader
类进行解析的过程中,读取编码后的值并将其更改为纯文本值吗?
c)根据输入文件是否相同,使用Base64编码或纯文本将值写回到输出中.
如果您可以将我引向有帮助的类或方法,那将是很好的.
^ ]
确定字符串是否以64为基数编码 [ ^ ] 从理论上讲,不可能确定数据是否为Base64.此格式没有任何格式指示符,这是有充分理由的.格式检测的整个思路是错误的,不能严格执行.在所有情况下,您都需要一些元数据.
对于base64转换,请使用System.Convert类,请参见 http://msdn.microsoft.com/en -us/library/system.convert.aspx [ ^ ].您可以使用其方法:<code>
FromBase64CharArray,FromBase64String
,ToBase64CharArray
,ToBase64String
.
—SA
I''m parsing an XML file and its values may or may not be Base64-encoded.
I''m reading an XML file with XmlReader
and then writing it back out to an output file (after I''ve fiddled with the values of some of the elements).
If the input file was Base64-encoded, the output file needs to be as well.
How do I
a) tell if the values are Base64 encoded or not in the first place?
And if so...
How do I
b) Read the encoded value and change it into a plaintext value during parsing using an XmlReader
class?
c) Write the value back out to the output either with Base64 encoding or plaintext, depending on whether the input file was the same.
If you could point me to a class or method that would help out that would be great.
Thanks.
Converting Base64[^]
Determine If A String Is Base 64 Encoded[^]
It is theoretically impossible to tell if the data is Base64 or not. This format does not have any indicator of the format, and for a good reason. The whole idea of format detection is wrong and cannot be strictly implemented. In all cases, you need some meta-data.
For base64 conversions use the class System.Convert, see http://msdn.microsoft.com/en-us/library/system.convert.aspx[^]. You can use its methods:<code>
FromBase64CharArray,FromBase64String
,ToBase64CharArray
,ToBase64String
.
—SA
这篇关于[已解决] XML文件中的Base64值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!