如何修复格式错误的XML? [英] How to repair malformed XML?

查看:692
本文介绍了如何修复格式错误的XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用PHP修复格式错误的XML文件的最佳实践是什么?例如,CDATA部分包含非法字符.有正则表达式吗?还是执行一些Linux命令行工具?

What is best practice to repair malformed XML files with PHP? For example CDATA part contains illegal chars. With regular expressions? Or execute some Linux command line tools?

推荐答案

整洁

Tidy是Tidy HTML的绑定 清洁和维修实用程序,它允许 您不仅要清洁,否则 处理HTML文档,而且 遍历文档树.

Tidy is a binding for the Tidy HTML clean and repair utility which allows you to not only clean and otherwise manipulate HTML documents, but also traverse the document tree.

// Specify configuration
$config = array(
           'indent'     => true,
           'input-xml'  => true,
           'output-xml' => true,
           'wrap'       => false);
// Tidy
$tidy = new tidy;
$tidy->parseFile('sample.xml', $config);
$tidy->cleanRepair();
// Output
echo $tidy;

这篇关于如何修复格式错误的XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆