Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试使用查询路径解析 NewsML (http://www.iptc.org/std/NewsML-G2/2.7/examples/LISTING2_NewsML-G2_Complete.xml) 文档。但我对某些元素中的点有疑问,比如<body.head>.
<body.head>
在一些 Firefox 查询路径插件中,我可以用反斜杠转义点,但在 php pear 库中,这不起作用。
有任何想法吗?
(我在 Querypath 中寻找解决方案,而不是解决方法)
过去,我使用 Tidy PHP 扩展 (http://us3.php.net/manual/en/book.tidy.php) 在将 HTML/XML 传递到 QueryPath 之前对其进行清理。
您在上面引用的 XML 非常干净,而且非常小。
如果唯一的问题是元素名称中的点,那么使用正则表达式进行预处理也可能会起作用。这将是最快的解决方案。我猜你可以做一个preg_replace('/<body\./g', '<body-', $xml)并修复它。(这将替换body.content为body-content等等。)
preg_replace('/<body\./g', '<body-', $xml)
body.content
body-content