tags:

views:

29

answers:

4

Hi,

Is displaying these two ways the same and correct?

E.g.

< contents cpid="1" cpnm="1">< /contents >

and

< contents
cpid="1"
cpnm="1">
< /contents>

+1  A: 

Yes, as far as the attributes are concerned.

lindelof
+1  A: 

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"/>
spender
+1  A: 

Your last example has a newline inside the contents. This can make a difference, at least with some XML parsers with some settings applied.

erikkallen
A: 

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

erwinston