SimpleXMLElement 修改根标签
美好的一天,
我在 PHP 中使用 SimpleXMLElement 修改 XML 时遇到问题。
我的XML结构如下:
<chart caption='NULL' shownames='1' showvalues='0' decimals='2' numberPrefix='$' useRoundEdges='0' legendBorderAlpha='0' bgColor='FFFFFF' canvasBorderColor='A5A5A5' canvasBorderThickness='1' showToolTip='1'>
...
</chart>
如何使用SimpleXMLElement修改根标签上的attributes()?
谢谢你!
编辑: 嗯...我找到了一种方法,但我不相信它很干净。我添加了一个
标记来包装我的 XML 数据。我最终将 str_replace(array("
添加到我的代码中。有什么想法是..“更清洁”吗?
Good day,
I am having trouble modifying XML using SimpleXMLElement in PHP.
My XML structure is as below:
<chart caption='NULL' shownames='1' showvalues='0' decimals='2' numberPrefix='
How can I modify the attributes() on the root tag using SimpleXMLElement?
Thank you!
EDIT:
Hmm... I found a way but I dont believe its very clean. I added a <root><chart ...>...</chart></root>
tag wraping my XML data. And I finally added str_replace(array("<root>", "</root>"), "", $_RenderedXML->asXML())
to my code. Any idea that is.. "cleaner"?
useRoundEdges='0' legendBorderAlpha='0' bgColor='FFFFFF' canvasBorderColor='A5A5A5' canvasBorderThickness='1' showToolTip='1'>
...
</chart>
How can I modify the attributes() on the root tag using SimpleXMLElement?
Thank you!
EDIT:
Hmm... I found a way but I dont believe its very clean. I added a <root><chart ...>...</chart></root>
tag wraping my XML data. And I finally added str_replace(array("<root>", "</root>"), "", $_RenderedXML->asXML())
to my code. Any idea that is.. "cleaner"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将“shownames”属性更改为(字符串)“2”
TO change the "shownames" attribute to (String) "2"