<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>47768</bug_id>
          
          <creation_ts>2010-10-16 07:30:48 -0700</creation_ts>
          <short_desc>XMLSerializer serializes BR as &lt;BR&gt; not &lt;BR/&gt;</short_desc>
          <delta_ts>2023-03-27 08:50:21 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>XML</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>CONFIGURATION CHANGED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>0</everconfirmed>
          <reporter name="Dave Raggett">dsr</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>annevk</cc>
    
    <cc>ap</cc>
    
    <cc>cdumez</cc>
    
    <cc>christoph.burgmer</cc>
    
    <cc>peterx14</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>295129</commentid>
    <comment_count>0</comment_count>
      <attachid>70953</attachid>
    <who name="Dave Raggett">dsr</who>
    <bug_when>2010-10-16 07:30:48 -0700</bug_when>
    <thetext>Created attachment 70953
Reproduce XML serialization error for HTML br element

My browser is Chromium	6.0.472.62 (Developer Build 59676) Ubuntu 10.04, WebKit	534.3 V8 2.2.24.23.

I am using XMLSerializer.serializeToString to serialize an HTML element and its content to XML. Unfortunately serializing content including a BR element then results in malformed XML. This is a nuisance when serializing markup to a server for download by other browsers, e.g. as part of a browser-based document editor.

Other browsers e.g. Firefox get this right.

Try viewing the attached HTML document in webkit, Opera and Firefox to see what I mean.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>295177</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2010-10-16 17:17:06 -0700</bug_when>
    <thetext>That&apos;s more or less intentional behavior. WebKit makes the serialization form choice based on what is being serialized, not on what API happened to be used.

See also: bug 16496.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>295205</commentid>
    <comment_count>2</comment_count>
    <who name="Dave Raggett">dsr</who>
    <bug_when>2010-10-17 02:41:34 -0700</bug_when>
    <thetext>If you want to get an HTML serialization, then you can use innerHTML, but the XML serialization should be XML for interoperability with other browsers.

I did some more experiments and found that regardless of the namespace of the parent element, BR is only serialized by webkit as well formed XML if you set its namespace to be something other than &quot;http://www.w3.org/1999/xhtml&quot;.

Thus the webkit implementation seems to be examining the namespace for each element and switching its serialization on the fly with the end result that you can&apos;t get well formed XML if there were any empty elements in the &quot;http://www.w3.org/1999/xhtml&quot; namespace.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>295251</commentid>
    <comment_count>3</comment_count>
      <attachid>70980</attachid>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2010-10-17 11:49:46 -0700</bug_when>
    <thetext>Created attachment 70980
XHTML test case

&gt; If you want to get an HTML serialization, then you can use innerHTML

This is not accurate in XML documents per HTML5. See &lt;http://www.whatwg.org/specs/web-apps/current-work/multipage/apis-in-html-documents.html#innerhtml&gt;:

-----------------------------
On getting, if the node&apos;s document is an HTML document, then the attribute must return the result of running the HTML fragment serialization algorithm on the node; otherwise, the node&apos;s document is an XML document, and the attribute must return the result of running the XML fragment serialization algorithm on the node instead (this might raise an exception instead of returning a string).
-----------------------------

So, innerHTML changes its behavior depending on what&apos;s being serialized.

&gt;  but the XML serialization should be XML for interoperability with other browsers.

There is no dispute about that being a strong argument for adopting Firefox behavior.

&gt; I did some more experiments and found that regardless of the namespace of the parent element,
&gt; BR is only serialized by webkit as well formed XML if you set its namespace to be something other
&gt; than &quot;http://www.w3.org/1999/xhtml&quot;.

This is not what I&apos;m seeing on the attached test case.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>726176</commentid>
    <comment_count>4</comment_count>
    <who name="Peter Ryan">peterx14</who>
    <bug_when>2012-09-22 14:27:12 -0700</bug_when>
    <thetext>My browser: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.10 (KHTML, like Gecko) Ubuntu/12.04 Chromium/23.0.1262.0 Chrome/23.0.1262.0 Safari/537.10

Example 1: HTML served as text/html
http://clickindustrial.com/test/public/20120908/test01.html

Example 2: XHTML served as text/html
http://clickindustrial.com/test/public/20120908/test02.html

Example 3: XHTML served as application/xhtml+xml
http://clickindustrial.com/test/public/20120908/test02.xhtml

Only example 3 outputs well-formed XML, which isn&apos;t what I&apos;d expect an XMLSerializer to do!

This is also inconsistent with Firefox and Opera:
http://clickindustrial.com/test/public/20120908/test01.png

^ the above screenshots are based on Example 1 above.

If a page is marked-up as HTML or is XHTML but served as text/html, there appears to be no way in WebKit to serialize it as XML, short of creating a new XML DOM, walking to HTML DOM and re-creating elements in the XML DOM.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>726276</commentid>
    <comment_count>5</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2012-09-23 10:44:44 -0700</bug_when>
    <thetext>&gt; Only example 3 outputs well-formed XML, which isn&apos;t what I&apos;d expect an XMLSerializer to do!

As mentioned in comments 1, this is not what WebKit implements - XMLSerializer just serializes the document without magically converting it to a different kind of a document.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>726658</commentid>
    <comment_count>6</comment_count>
    <who name="Peter Ryan">peterx14</who>
    <bug_when>2012-09-24 07:48:11 -0700</bug_when>
    <thetext>Just to clarify, my point is that I&apos;d expect something called &quot;XMLSerializer&quot; to generate XML. If it does not do this, then it should surely be called just plain &quot;Serializer&quot;. And therefore, being called XMLSerializer and not outputting XML must therefore be a bug?

Additionally, I can&apos;t think-of/find a viable alternative or work-around (tree-walking, DOM copying is kind of slow!). For my use-case, I need well-formed XML in order to push it through an XSL transformation. Conversely, if XMLSerializer actually output XML, it would be trivial to convert XHTML to HTML using a simple XSL transformation.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>726705</commentid>
    <comment_count>7</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2012-09-24 08:42:17 -0700</bug_when>
    <thetext>&gt; I&apos;d expect something called &quot;XMLSerializer&quot; to generate XML

I see where you are coming from, but can&apos;t really subscribe to this line of thinking. XMLHttpRequest doesn&apos;t have much to do with XML either.

XSLT has a lot of rough edges when used on the Web - in fact, you can&apos;t even produce &lt;br&gt; without violating the spec, see &lt;https://www.w3.org/Bugs/Public/show_bug.cgi?id=18460&gt;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>950578</commentid>
    <comment_count>8</comment_count>
    <who name="Christoph Burgmer">christoph.burgmer</who>
    <bug_when>2013-11-14 02:51:58 -0800</bug_when>
    <thetext>As I was hit by the same limitation I sat down to implement a serializer in plain JS. I now hope that this can benefit others. You&apos;ll find a demo here: http://cburgmer.github.io/xmlserializer.js/.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1944255</commentid>
    <comment_count>9</comment_count>
    <who name="Anne van Kesteren">annevk</who>
    <bug_when>2023-03-27 08:50:21 -0700</bug_when>
    <thetext>This appears to have been fixed at some point.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>70953</attachid>
            <date>2010-10-16 07:30:48 -0700</date>
            <delta_ts>2010-10-16 07:30:48 -0700</delta_ts>
            <desc>Reproduce XML serialization error for HTML br element</desc>
            <filename>test.html</filename>
            <type>text/html</type>
            <size>961</size>
            <attacher name="Dave Raggett">dsr</attacher>
            
              <data encoding="base64">PGh0bWwgbGFuZz0iZW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cmlh
bGl6ZWQgYXMgbWFsZm9ybWVkIFhNTCBhcyAmbHQ7YnImZ3Q7IGluc3RlYWQgb2YKJmx0O2JyIC8m
Z3Q7IGFzIGhhcHBlbnMgd2hlbiB5b3UgdmlldyB0aGlzIHBhZ2UgaW4gRmlyZWZveAphbmQgT3Bl
cmEuPC9wPgoKPHByZSBpZD0ibWFya3VwIj48L3ByZT4KPC9ib2R5Pgo8L2h0bWw+Cg==
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>70980</attachid>
            <date>2010-10-17 11:49:46 -0700</date>
            <delta_ts>2010-10-17 11:49:46 -0700</delta_ts>
            <desc>XHTML test case</desc>
            <filename>serialize-br.xhtml</filename>
            <type>application/xhtml+xml</type>
            <size>169</size>
            <attacher name="Alexey Proskuryakov">ap</attacher>
            
              <data encoding="base64">PGh0bWwgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGh0bWwiPgo8aGVhZD48dGl0bGUv
PjwvaGVhZD4KPGJvZHk+Cjxici8+CjxzY3JpcHQ+CmFsZXJ0KChuZXcgWE1MU2VyaWFsaXplciku
c2VyaWFsaXplVG9TdHJpbmcoZG9jdW1lbnQpKTsKPC9zY3JpcHQ+CjwvYm9keT48L2h0bWw+Cg==
</data>

          </attachment>
      

    </bug>

</bugzilla>