简体   繁体   English

循环浏览XML文件中的所有字符并替换某些字符

[英]Loop through all characters in XML file and replace certain characters

After finally getting my XmlReader to work correctly on a project at work, I am now getting certain parsing errors when trying to create new Reader objects for certain XML files. 最终使我的XmlReader在工作中的项目上正常工作之后,当尝试为某些XML文件创建新的Reader对象时,我现在遇到某些解析错误。 For instance, this one that keeps occurring is an error trying to parse a hyphen (-). 例如,这种不断发生的错误是试图解析连字符(-)的错误。 This slightly baffles me because I manually go in and replace that character with something else (like an underscore), and it reads fine - even when there are hyphens elsewhere in the document that are not changed. 这让我有些困惑,因为我手动输入该字符并将其替换为其他字符(例如下划线),并且即使在文档中其他地方没有连字符的连字符都未更改的情况下,它也可以正常读取。

So, unless there is a explanation to fix this (maybe some XmlReaderSettings? Have yet to use any so I don't know what they are capable of), what is the best syntax/method to cycle through every character and replace with ones that will parse correctly? 因此,除非有解决此问题的解释(也许有些XmlReaderSettings?尚未使用任何方法,所以我不知道它们的功能),否则最好的语法/方法是循环遍历每个字符并替换为将正确解析?

This program will run automatically once per day on a daily-added XML and length of run-time is not an issue. 该程序将每天自动在每天添加的XML上运行一次,运行时间的长短不是问题。

Edit: Error Message: 编辑:错误消息:

System.Xml.XmlException: An error occurred while parsing EntityName. System.Xml.XmlException:解析EntityName时发生错误。 Line 2896, position 89. 2896行,位置89。

Code: 码:

            FN = Path.GetFileName(file1).ToString()
        xmlFile = XmlReader.Create(Path.Combine(My.Settings.Local_Meter_Path, FN), New XmlReaderSettings())
        ds.ReadXml(xmlFile)
        Dim dt As DataTable = ds.Tables(13)
        Dim filecreatedate As String = IO.File.GetLastWriteTime(file1)

If the problem occurs in ONLY ONE HYPHEN in entire file, even if the file contains more hyphens, the problem may be related to: 如果在整个文件中仅一个连字符出现问题,即使该文件包含更多连字符,则该问题可能与以下问题有关:

1) The HYPHEN is really not an HYPHEN but a control-character or even be accomplished of a hidden control character. 1)连字符实际上不是连字符,而是控制字符,甚至是隐藏的控制字符。

2) The link has other interesting thinhs, like an ampersand ("&"), which in strings may cause some problems. 2)链接还有其他有趣的稀疏字符,例如&符(“&”),它在字符串中可能会引起一些问题。 Are you sure the problem is the Hyphen? 您确定问题是连字符吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM