如何使用 PHP 反序列化 MXML?
我有一个必须转换为 MXML 的数组结构。我知道 PEAR XML_Serialize 扩展,但它产生的输出格式似乎有点不同.
PHP 生成的 XML:
<zone columns="3">
<select column="1" />
<select column="4" />
</zone>
MXML 格式:
<mx:zone columns="3">
<mx:select column="1" />
<mx:select column="4" />
</mx:zone>
所有标签都需要“mx:”前缀吗?如果是,我可以让 XML_Serialize
将其放在每个标签之前(而不将我的数据结构字段重命名为“mx:something”)吗?
以下是我的 XML_Serialize
选项:
$aOptions = array('addDecl' => true, 'indent' => " ", 'rootName' => 'template',
'scalarAsAttributes' => true, 'mode' => 'simplexml');
I have an array structure that have to be converted to MXML. I know of PEAR XML_Serialize extension but it seems the output format it produces is a bit different.
PHP generated XML:
<zone columns="3">
<select column="1" />
<select column="4" />
</zone>
MXML format:
<mx:zone columns="3">
<mx:select column="1" />
<mx:select column="4" />
</mx:zone>
Is that "mx:" prefix required for all the tags? If yes, can I make the XML_Serialize
put it before each tag (without renaming my data structure fields to "mx:something")?
Here are my options for XML_Serialize
:
$aOptions = array('addDecl' => true, 'indent' => " ", 'rootName' => 'template',
'scalarAsAttributes' => true, 'mode' => 'simplexml');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在序列化程序中缺少名称空间声明。像这样向序列化器添加一个命名空间:
您还可以将其添加到您的 $aOptions 数组:
关于是否需要命名空间 - 这实际上取决于您的 XML 声明的样子。如果默认命名空间已设置为 MXML,则不 - 不需要。
You're missing the namespace declaration in your serializer. Add a namespace to your serializer like this:
You could also add it your $aOptions array:
In regard to whether the namespace is required - this really depends on what your XML declarations look like. If the default namespace is set to MXML already, then no - its not required.