Is displaying these two ways the same and correct?
E.g.
< contents cp开发者_如何转开发id="1" cpnm="1">< /contents >
and
< contents
cpid="1" cpnm="1"> < /contents>Your last example has a newline inside the contents. This can make a difference, at least with some XML parsers with some settings applied.
Yes, as far as the attributes are concerned.
Yes. XML generally ignores whitespace, although you can turn this feature on/off in most XML processors. Within a tag, it makes no difference whatsoever.
This is also equivalent:
<contents cpid="1" cpnm="1"/>
No! Both contain different count of XML nodes.
If you try to get the first child in the first case, you get nothing. In the second case, you get a text element with a simple '\n' content.
Even in XSLT transformations you may get different results - watch for e.g. "position()" function of XPath.
More information: http://www.oracle.com/technology/pub/articles/wang-whitespace.html
精彩评论