gpt4 book ai didi

javascript - AngularJS 部分中的大小写敏感度

转载 作者:行者123 更新时间:2023-11-28 01:34:09 25 4
gpt4 key购买 nike

我有一个包含 XML 的部分,我将其包含在另一个部分中。

<rootNode>
<firstName>{{ user.name }} </firstName>
<age>{{ user.age }}</age>
</rootNode>

如果我将其用作 <div ng-include="partials/test.xml"></div> 的部分内容,变量表现良好,但所有标签现在都是小写的。

<rootnode>
<firstname>Austin</firstname>
<age>27</age>
</rootnode>

该 XML 不会根据需要正确大小写的模式进行验证。

有没有办法告诉ng-include指令以保持大小写相同,或者我是否需要使用另一个库(如 Mustache)来执行此类模板?

最佳答案

可以自定义内部转换,通过修改 jqLit​​e(或 jQuery,如果可用)来强制保留大小写,从而规范化 elements to be lowercase通过 toLowerCase 方法。

否则, native XMLSerializer 似乎是特定于浏览器的:

DOM handling is very confusing if you have tags containing uppercase letters together with lowercase letters. This is due to the XHTML standard: XHTML is case sensitive, and since XHTML only accepts lower case HTML tags and attribute names, a general search and replace function was executed to replace all upper case tags with lowercase tags. But IE has ignored this aspect of XHTML standard by simply running all XML operations protecting the case-sensitivity. This is much more convenient since XML standard itself is case-sensitive.

Below are the conflicting behaviors of XML handling in Firefox:

  1. All xhtml tags are converted into LOWERCASE because of XHTML compatibility

  2. nodeName getter for Element object returns in UPPERCASE

  3. XMLDocument object keeps the dom document by converting all tags to UPPERCASE

  4. XMLSerializer.serializeToString returns all the tag names in UPPERCASE

Hence, writing robust code that perform both server-side and client-side XML operations is always difficult with this conflicting case-insensitive DOM handling. Coming versions must handle this issue by supporting case-sensitivity.

引用文献

关于javascript - AngularJS 部分中的大小写敏感度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21735025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com