如何使用 PHP 反序列化 MXML?

发布于 2024-08-30 02:54:22 字数 813 浏览 6 评论 0原文

我有一个必须转换为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零時差 2024-09-06 02:54:22

您在序列化程序中缺少名称空间声明。像这样向序列化器添加一个命名空间:

$serializer->setOption('namespace', array('mx', 'http://ns.adobe.com/mxml/2009'));

您还可以将其添加到您的 $aOptions 数组:

$aOptions = array(
  'addDecl' => true,
  'indent' => "    ",
  'rootName' => 'template',
  'scalarAsAttributes' => true,
  'mode' => 'simplexml',
  'namespace' =>array('mx', 'http://ns.adobe.com/mxml/2009')
);

关于是否需要命名空间 - 这实际上取决于您的 XML 声明的样子。如果默认命名空间已设置为 MXML,则不 - 不需要。

You're missing the namespace declaration in your serializer. Add a namespace to your serializer like this:

$serializer->setOption('namespace', array('mx', 'http://ns.adobe.com/mxml/2009'));

You could also add it your $aOptions array:

$aOptions = array(
  'addDecl' => true,
  'indent' => "    ",
  'rootName' => 'template',
  'scalarAsAttributes' => true,
  'mode' => 'simplexml',
  'namespace' =>array('mx', 'http://ns.adobe.com/mxml/2009')
);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文