0

How to differ

<bar />

and

<bar></bar>

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>');

Is it possible somewhat? Thank you

kjhughes
  • 106,133
  • 27
  • 181
  • 240
user2301515
  • 4,903
  • 6
  • 30
  • 46

1 Answers1

3
<bar/>

and

<bar></bar>

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

Update per comment pressing the point:

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.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • I try to ask again, is it possible. How DOMDocument can know, if 'child' (of xml given as string) is or ? Thank you – user2301515 Jan 17 '15 at 09:49