doucongqian6644 2017-03-07 16:45
浏览 55

DOMDocument库从标记名称中删除冒号

Let's suppose I have a HTML tag <ui:button> which refers to a button on a web page and will eventually be turned into new UIButton() in PHP.

When using the DOMDocument library, the $tagName property of the element is just button. Why is this and how can I retain ui: in it?

  • 写回答

1条回答 默认 最新

  • doucu7525 2017-03-08 09:37
    关注

    The ui is a namespace alias/prefix. Look for an attribute like xmlns:ui="...". The value of that attribute is an URN, a unique string defining the format the tags are part of. Often URLs are used for that purpose, because it avoids conflicts (nobody is going to use on of your domains for a namespace) and you can put documentation about the namespace on the URL. Namespaces are an XML feature that allows you to define and mix formats without conflicts between the element node names.

    Let's say the attribute looks like xmlns:ui="http://example.tld/ns/ui". In this case you can read the tag name as {http://example.tld/ns/ui}button. Writing it that way would add a lot of overhead and make the XML difficult to read - hence the prefixes/aliases.

    The following 3 XMLs all can be read as {http://example.tld/ns/ui}button

    • <ui:button xmlns:ui="http://example.tld/ns/ui"/>
    • <new-ui:button xmlns:new-ui="http://example.tld/ns/ui"/>
    • <button xmlns="http://example.tld/ns/ui"/>

    As you can see the alias can change and is optional. If you check the properties of DOMNode you will see the properties $namespaceURI and $locaName. Build you application using them not $nodeName. Here are methods with the suffix NS that are namespace aware.

    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)