[ 
https://issues.apache.org/jira/browse/XERCESJ-1602?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18142108#comment-18142108
 ] 

Elliotte Rusty Harold commented on XERCESJ-1602:
------------------------------------------------

### Pure XML vs. XHTML Compatibility

In pure XML, `<script></script>` and `<script/>` are semantically identical. 
Any conforming XML parser treats self-closing tags and empty start/end tag 
pairs as equivalent.

However, the statement in question originates from **W3C XHTML 1.0 Appendix C 
("HTML Compatibility Guidelines")**.

### Why the Distinction Matters

When XHTML 1.0 was released, the goal was allowing documents written in XML 
syntax to be served to legacy web browsers using an `text/html` MIME type 
(rather than `application/xhtml+xml`).

HTML parsers (HTML4 and HTML5) do not parse XML. They follow SGML/HTML parsing 
rules:

1. **HTML Void Elements** (e.g., `<img>`, `<br>`, `<input>`, `<meta>`, 
`<link>`):
* HTML parsers recognize these elements as inherently empty.
* In XHTML, writing `<br />` or `<img src="..." />` works in both HTML and XML 
parsers.


2. **HTML Non-Void Elements** (e.g., `<script>`, `<div>`, `<iframe>`, 
`<textarea>`, `<title>`):
* HTML parsers do **not** recognize the self-closing `/` trailing slash on 
non-void elements.
* If an HTML parser encounters `<script src="app.js" />`, it ignores the `/` 
and treats it as an unclosed opening `<script>` tag. Everything following it in 
the document gets parsed as inline JavaScript until it encounters an explicit 
`</script>` end tag, breaking the entire page layout.



### Summary

* **Pure XML/XHTML Specs:** Any element can be self-closing (`<div/>` is valid 
XML).
* **HTML Compatibility (Appendix C / `text/html` serving):** Non-void elements 
**must** use an explicit closing tag (e.g., `<script></script>`, `<div/>` is 
forbidden) so that standard HTML parsers can process the document correctly.

> Iframe element is serialized incorrectly
> ----------------------------------------
>
>                 Key: XERCESJ-1602
>                 URL: https://issues.apache.org/jira/browse/XERCESJ-1602
>             Project: Xerces2-J
>          Issue Type: Bug
>          Components: Serialization
>    Affects Versions: 2.11.0
>         Environment: java version "1.6.0_24"
> Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
> Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode, sharing)
>            Reporter: Nasir Hussain
>            Assignee: Elliotte Rusty Harold
>            Priority: Major
>         Attachments: XercesTest.java
>
>
> when we try to serialize iframe element such as <iframe frameborder="0" 
> height="250" src="http://www.youtube.com/embed/w2CsEUn4ZuU"; 
> width="418"></iframe>
> The serialized output is:
> <iframe  frameborder="0" height="250" 
> src="http://www.youtube.com/embed/w2CsEUn4ZuU"; width="418" />
> This is invalid html after serialization, iframe element must be closed using 
> '</iframe>' tag not by '/>'
> The sample code for reproducing this problem is attached on the issue.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to