且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

正则表达式,用于检查字符串是否为有效XML

更新时间:2022-03-03 23:23:22

无法通过常规验证XML表达式。 XML不是常规语言

It's not possible to validate XML with regular expressions. XML is not a regular language.

使用XML解析器尝试将字符串解析为XML,或者根据模式验证XML文档,例如 DTD XSD 文件。

Use an XML parser to try to parse the string as XML or else validate the XML document against a schema, for example a DTD or XSD file.