在 SimpleXML for PHP 中关闭自闭合标签? [英] Turn OFF self-closing tags in SimpleXML for PHP?

查看:30
本文介绍了在 SimpleXML for PHP 中关闭自闭合标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个带有 PHP 的 SimpleXML 扩展的 XML 文档,我正在向文件中添加一个标记:

I'm building an XML document with PHP's SimpleXML extension, and I'm adding a token to the file:

$doc->addChild('myToken');

这会生成(我所知道的)一个自闭合标签或单个标签:

This generates (what I know as) a self-closing or single tag:

<myToken/>

但是,我正在与之通信的老化网络服务正在被自闭标签绊倒,所以我需要有一个单独的开始和结束标签:

However, the aging web-service I'm communicating with is tripping all over self-closing tags, so I need to have a separate opening and closing tag:

<myToken></myToken>

问题是,除了通过 preg_replace 运行生成的 XML 之外,我该怎么做?

The question is, how do I do this, outside of running the generated XML through a preg_replace?

推荐答案

来自 SimpleXMLElement->__constructLibXML 预定义常量,我认为这应该有效:

From the documentation at SimpleXMLElement->__construct and LibXML Predefined Constants, I think this should work:

<?php
$sxe = new SimpleXMLElement($someData, LIBXML_NOEMPTYTAG);

// some processing here

$out = $sxe->asXML();
?>

试试看是否有效.否则,恐怕就是 preg_replace-land.

Try that and see if it works. Otherwise, I'm afraid, it's preg_replace-land.

这篇关于在 SimpleXML for PHP 中关闭自闭合标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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