dsfw2154 2011-09-05 08:20
浏览 57
已采纳

是否可以使用默认命名空间(xmlns)和指向同一URI的带前缀的命名空间?

We're trying to generate some namespaced XML (attributes and all) but we're noticing some issues when outputting prefixes with both SimpleXML and DOMDocument in PHP. This is our test output:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:a="http://default" xmlns:b="http://extra" xmlns="http://default">
  <a:test_default>alpha</a:test_default>
  <b:test_extra>bravo</b:test_extra>
</root>

The reason I ask - we wanted to include the attributes in the namespace, but we're aware that attributes do not take the namespace of their containing element. We normally have a default namespace for our nodes. Thus, we concluded a prefix namespaced declaration would also be needed. However, when generating XML via SimpleXML or DOMDocument, prefixes are never added to the attributes.

Is there a better way? We were trying to avoid prefixing every element in the XML - utilising the default to make the content more readable.

  • 写回答

1条回答 默认 最新

  • doukui2011 2011-09-05 09:55
    关注

    Yes, it's quite OK to do this. It's often done in XSD, for example.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于#flink#的问题:关于docker部署flink集成hadoop的yarn,请教个问题flink启动yarn-session.sh连不上hadoop
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题