正则表达式检查 XML 是否格式正确 [英] Regex to check for XML if it is well formed
问题描述
是否有正则表达式用于检查 xml 格式是否正确?
Is there a regex for checking if the xml is well formed ?
谢谢
如果不是正则表达式,那么是否有一个很好的解析方法,我可以在 c# 中使用它不会抛出异常.我尝试使用 xmlReader 但它对我不起作用.
If not regex, then is there a good parsing method that i can use in c# that doesnt throw exception. I tried using xmlReader but it didnt work for me.
推荐答案
这超出了正则表达式的能力.换句话说,答案是不可能.
This is well beyond the capabilities of regular expressions. In other words, the answer is that it's not possible.
有很多工具可用于检查格式是否正确,但它们都涉及某种 XML 解析器/验证器.如果您提供有关您的环境的更多信息,也许我们可以为您指明正确的方向.
There are plenty of tools available to check well-formedness, but they all involve some sort of XML parser/validator. If you provide more information about your environment maybe we can point you in the right direction.
这篇关于正则表达式检查 XML 是否格式正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!