Friday, 15 February 2013

php - self closing tags in XML files -



php - self closing tags in XML files -

<tag id="foo" />

i noticed work php simplexml :d

but xml examples found on web close them old way:

<tag id="foo"></tag>

is there reason why should utilize old method?

see w3c specs xml , xhtml:

http://www.w3.org/tr/xml/#sec-starttags http://www.w3.org/tr/xhtml1/dtds.html#a_dtd_xhtml-1.0-strict

it depends on element type declaration

an element no content said empty. representation of empty element either start-tag followed end-tag, or empty-element tag.

but

empty-element tags may used element has no content, whether or not declared using keyword empty. interoperability, empty-element tag should used, , should used, elements declared empty.

this means, when dtd contains like

<!element img empty>

you should use

<img/>

unless have reason use

<img></img>

note should defined in rfc2119 as

this word, or adjective "recommended", mean there may exist valid reasons in particular circumstances ignore particular item, total implications must understood , weighed before choosing different course.

if working xml not have dtd or schema, can influence how xml serialized predefined libxml constant:

libxml_noemptytag (integer): expand empty tags (e.g. <br/> <br></br>)

but note alternative available in functions domdocument::save , domdocument::savexml, cannot utilize simplexml.

php html xml tags

No comments:

Post a Comment