内联XMLNS为什么会更改整个标签结构?联合部队 [英] why would an inline XMLNS change the entire tag structure? JSF

查看:82
本文介绍了内联XMLNS为什么会更改整个标签结构?联合部队的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提前致歉,我没有做很多前端开发.但简而言之,xmlns属性是删除标记并将其在渲染的文档中移动.这可能是一个JSF问题,因为它甚至发生在视图源中.此svg标记有效且不会更改结构:

My apologies in advance, i don't do a lot of front end development. But in short xmlns attributes are removing tags and moving them around in the rendered document. This is probably a JSF issue as it even happens in view source. This svg tag works and does not alter the structure:

<svg id="Layer_1"  x="0px" y="0px" width="150px" height="150px" viewBox="0 0 150 150" enable-background="new 0 0 150 150">

但是,一旦声明了xml名称空间,页面上的所有代码都会被更改.它移动我的span标签,一个标签,header标签,删除关闭的div标签,并以破坏所有内容的方式对其进行排序.这是原始xhtml的示例,并呈现了xhtml和html的xmlns

But as soon as an xml namespace is declared, all the code on the page is altered. It moves my span tags, a tags, heading tags, removes closing div tags, and orders them in a way that just breaks everything. here is an example of the original xhtml, and rendered xhtml along with the html's xmlns

jsf之前的xhtml:

pre-jsf xhtml:

 <a href="?service=all" class="#{servicesAllClass}">
                      <span>
                          <svg **xmlns="http://www.w3.org/2000/svg"**  id="Layer_1"  x="0px" y="0px"
                               width="150px" height="150px" viewBox="0 0 150 150" enable-background="new 0 0 150 150">
                            <path fill="#3A3838" d="M126.83,8.875H22.169c-7.116,0-12.884,5.768-12.884,12.884v102.482c0,7.115,5.768,12.884,16.884,12.884
                                H130.83c3.116,0,8.884-5.769,8.884-12.884V21.759C139.714,14.643,133.946,8.875,126.83,8.875z M38.643,118.505
                                c-5.93,0-10.737-4.807-10.737-10.737c0-5.93,4.807-10.736,10.737-10.736s10.736,4.807,10.736,10.736
                                C49.379,113.698,44.573,118.505,38.643,118.505z M38.643,83.736c-5.93,0-10.737-4.806-10.737-10.736
                                c0-5.93,4.807-10.737,10.737-10.737S49.379,67.07,49.379,73C49.379,78.931,44.573,83.736,38.643,83.736z M38.643,48.969
                                c-5.93,0-10.737-4.807-10.737-10.737s4.807-10.736,10.737-10.736s10.736,4.806,10.736,10.736S44.573,48.969,38.643,48.969z
                                 M112.834,45.167H68.166c-4.418,0-8-3.582-8-8s3.582-8,8-8h44.668c4.418,0,8,3.582,8,8S117.252,45.167,112.834,45.167z
                                 M112.834,80.167H68.166c-4.418,0-8-3.581-8-8c0-4.418,3.582-8,8-8h44.668c4.418,0,8,3.582,8,8
                                C120.834,76.586,117.252,80.167,112.834,80.167z M112.834,115.167H68.166c-4.418,0-8-3.581-8-8s3.582-8,8-8h44.668
                                c4.418,0,8,3.581,8,8S117.252,115.167,112.834,115.167z"></path>
                            </svg>
                         </span>
                      <h5>All</h5>
                  </a>

这是JSF之后的代码,当xmlns位于标记中时,请注意缺少闭合锚标记,该标记没有被遗漏,只是不存在.但是,当删除xmlns时,它的显示与原始(上面的)脚本完全相同,因此我选择不包括它.

This is the code after JSF when xmlns is in the tag, notice the lack of a closing anchor tag, that was not left out, its just not there. When xmlns is removed however, it is displayed exactly the same as the original (above) script, so i have opted to not include it.

在任何浏览器中提取DOM(请注意缺少的锚标记,它像30行一样向下移动了

DOM when pulled in any browser (note the missing anchor tag, it was moved down like 30 lines)

<a href="?service=all-services" class="disabled">
                      <span><svg xmlns="http://www.w3.org/2000/svg" id="Layer_1" x="0px" y="0px" width="150px" height="150px" viewBox="0 0 150 150" enable-background="new 0 0 150 150">
                            <path fill="#3A3838" d="M126.83,8.875H22.169c-7.116,0-12.884,5.768-12.884,12.884v102.482c0,7.115,5.768,12.884,16.884,12.884                                     H130.83c3.116,0,8.884-5.769,8.884-12.884V21.759C139.714,14.643,133.946,8.875,126.83,8.875z M38.643,118.505                                     c-5.93,0-10.737-4.807-10.737-10.737c0-5.93,4.807-10.736,10.737-10.736s10.736,4.807,10.736,10.736                                     C49.379,113.698,44.573,118.505,38.643,118.505z M38.643,83.736c-5.93,0-10.737-4.806-10.737-10.736                                     c0-5.93,4.807-10.737,10.737-10.737S49.379,67.07,49.379,73C49.379,78.931,44.573,83.736,38.643,83.736z M38.643,48.969                                     c-5.93,0-10.737-4.807-10.737-10.737s4.807-10.736,10.737-10.736s10.736,4.806,10.736,10.736S44.573,48.969,38.643,48.969z                                      M112.834,45.167H68.166c-4.418,0-8-3.582-8-8s3.582-8,8-8h44.668c4.418,0,8,3.582,8,8S117.252,45.167,112.834,45.167z                                      M112.834,80.167H68.166c-4.418,0-8-3.581-8-8c0-4.418,3.582-8,8-8h44.668c4.418,0,8,3.582,8,8                                     C120.834,76.586,117.252,80.167,112.834,80.167z M112.834,115.167H68.166c-4.418,0-8-3.581-8-8s3.582-8,8-8h44.668                                     c4.418,0,8,3.581,8,8S117.252,115.167,112.834,115.167z"></path>
                            </svg>

                      <h5>All</h5>
                  </span>

所需的完整文件:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:jsp="http://java.sun.com/JSP/Page"   xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:c="http://xmlns.jcp.org/jsp/jstl/core" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets">
<head></head>
<body>
<ui:composition>
<div style="display:grid;">
 <a href="?service=all" class=".test">
                      <span>
                          <svg xmlns="http://www.w3.org/2000/svg"  id="Layer_1"  x="0px" y="0px"
                               width="150px" height="150px" viewBox="0 0 150 150" enable-background="new 0 0 150 150">
                            <path fill="#3A3838" d="M126.83,8.875H22.169c-7.116,0-12.884,5.768-12.884,12.884v102.482c0,7.115,5.768,12.884,16.884,12.884
                                H130.83c3.116,0,8.884-5.769,8.884-12.884V21.759C139.714,14.643,133.946,8.875,126.83,8.875z M38.643,118.505
                                c-5.93,0-10.737-4.807-10.737-10.737c0-5.93,4.807-10.736,10.737-10.736s10.736,4.807,10.736,10.736
                                C49.379,113.698,44.573,118.505,38.643,118.505z M38.643,83.736c-5.93,0-10.737-4.806-10.737-10.736
                                c0-5.93,4.807-10.737,10.737-10.737S49.379,67.07,49.379,73C49.379,78.931,44.573,83.736,38.643,83.736z M38.643,48.969
                                c-5.93,0-10.737-4.807-10.737-10.737s4.807-10.736,10.737-10.736s10.736,4.806,10.736,10.736S44.573,48.969,38.643,48.969z
                                 M112.834,45.167H68.166c-4.418,0-8-3.582-8-8s3.582-8,8-8h44.668c4.418,0,8,3.582,8,8S117.252,45.167,112.834,45.167z
                                 M112.834,80.167H68.166c-4.418,0-8-3.581-8-8c0-4.418,3.582-8,8-8h44.668c4.418,0,8,3.582,8,8
                                C120.834,76.586,117.252,80.167,112.834,80.167z M112.834,115.167H68.166c-4.418,0-8-3.581-8-8s3.582-8,8-8h44.668
                                c4.418,0,8,3.581,8,8S117.252,115.167,112.834,115.167z"></path>
                            </svg>
                         </span>
                      <h5>All</h5>
                  </a>
</div>
</ui:composition>
</body>
</html>

详细信息:

我明确的问题:将XML名称空间属性添加到元素时,可能导致dom更改的原因是什么?"

My clear question: "What could possibly cause the dom to be changed when an XML namespace attribute is added to an element?"

应用程序服务器+ IDE:Glassfish 5.0-Java EE 8-JSF 2.3.2-SCSS css预处理程序仅处理.scss文件-intellij IDEA Ultimate(最新)

application server + IDE: Glassfish 5.0 - Java EE 8 - JSF 2.3.2 - SCSS css pre-proccessor only processing .scss files - intellij IDEA Ultimate (Latest)

所有文件均为.xhtml,目前还没有托管Bean,代码或javascript以任何方式影响此效果.

all files are .xhtml, there are currently no managed beans, code, or javascript that in any way effect this.

如果将HTML放入没有JSF的tomcat中,则不会发生这种情况.这就是为什么我指的是JSF,但我可能不正确.

When html is put in tomcat without JSF this does not happen. This is why i am pointing at JSF but i may be incorrect.

推荐答案

我调试了一下,发现这一定是在JSF SAXCompiler例程中发生的. 当com.sun.faces.facelets.compiler.SAXCompiler.CompilationHandler按照XHTML源代码以正确的顺序调用其startElementendElement方法时,

I debugged a bit and found this must be happening in JSF SAXCompiler routines. While the com.sun.faces.facelets.compiler.SAXCompiler.CompilationHandler gets its' startElement and endElement methods invoked in correct order as per the XHTML source code, the result of

FaceletHandler h = this.compiler.compile(url, alias);

com.sun.faces.facelets.impl.DefaultFaceletFactory Mojarra 2.3.8的第475行的

是表示观察到的错误元素树结构的FaceletHandler.

at line 475 of com.sun.faces.facelets.impl.DefaultFaceletFactory Mojarra 2.3.8, is a FaceletHandler representing the observed wrong element tree structure.

这已报告为错误#4555 .

之前有一个非常相似的问题,当时,该问题报告为Mojarra的错误.解决该错误后,我认为这是一个新错误.因此,我建议您使用缩小的可复制示例报告该错误.对于您的应用程序,您应该考虑使用BalcC建议使用<ui:include src="/resources/svg/one.svg" />来使SVG充满活力,以响应其他问题.

There has also been a very similar question before which was then reported as a bug to Mojarra. As that bug is resolved, I'd consider this to be a new one. So I'd suggest you to report that bug using a minified reproducable example. For your application you should consider to emebed SVGs using <ui:include src="/resources/svg/one.svg" /> as BalusC suggest in response to the other question.

这篇关于内联XMLNS为什么会更改整个标签结构?联合部队的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆