带结束标记和不带结束标记的 XML(自关闭标记) [英] XML with end tag and without it (self-closing tag)

查看:72
本文介绍了带结束标记和不带结束标记的 XML(自关闭标记)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何区分

<bar />

<bar></bar>

使用 php DOMDocument 如下:

with php DOMDocument like:

<php
$xml = new DOMDocument("1.0", "UTF-8");
$xml->loadXML('<?xml version="1.0" encoding="UTF-8"?><foo><bar /><bar></bar></foo>');

有可能吗?谢谢

推荐答案

<bar/>

<bar></bar>

在 XML 中是等价的.XML 处理器会以相同的方式处理它们,您的软件也应该如此.

are equivalent in XML. XML processors will handle them identically, and your software should too.

作为 XML,它们是等效的.作为文本,它们是不同的.如果您希望控制这种对 XML 没有影响的差异,请将它们视为文本,而不是 XML. 但是请注意,您违背了规则.这种差异在 XML 级别上是微不足道的.

As XML, they are equivalent. As text, they are different. Treat them as text, not XML, if you wish to control this difference that makes no difference to XML. Be aware, though, that you're going against the grain. This difference is insignificant at the XML level.

这篇关于带结束标记和不带结束标记的 XML(自关闭标记)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆