Is it possible to comment one or several attributes inside an XML tag? Something like /* */
from C.
是否可以在XML标记内评论一个或多个属性?像/* */从C。
I have tried using <!-- -->
, but it was unsuccessful.
我试过使用 ,但不成功。
<element
attribute1="value1"
attribute2="value2"
<!-- attribute3="value3" (commented value) -->
>
4 个解决方案
#1
30
No, this isn't possible. Comments are not allowed in an XML open tag. Depending on your application, you might get away with "commenting out" the attributes by prefixing their names with "_", or you might not (if the XML is validated against a schema or all attributes are parsed). Because whitespace is allowed, and most editors support line operations, you can "comment" multiple attributes easily this way:
不,这是不可能的。在XML开放标记中不允许注释。根据应用程序的不同,您可以通过在属性名前面加上“_”来“注释掉”属性,也可以不这样做(如果根据模式验证XML或解析所有属性)。由于空格是允许的,并且大多数编辑器都支持行操作,所以您可以通过以下方式轻松“注释”多个属性:
<element
_attr1="value1"
_attr2="value2"
_attr3="value3"
>
But these attributes are still part of the document.
但是这些属性仍然是文档的一部分。
#2
11
The only compliant way is to create a node without the attribute in question. I regularly use this approach:
唯一兼容的方法是创建一个没有问题属性的节点。我经常使用这种方法:
<div>
<!-- This opening div tag replaces the one above.
<div my-attribute="my-value"> -->
div contents here...
</div>
The comment to clarify what the commented-out open tag is depends on your need (co-workers using this code, etc.).
注释来澄清什么是被注释掉的open标记取决于您的需要(同事使用此代码等)。
Then, when you need to shift things around, simply change it to:
然后,当你需要改变事情时,只需将它改为:
<!-- <div>
This opening div tag replaces the one below. -->
<div my-attribute="my-value">
div contents here...
</div>
Again, your need for commenting will change with each case.
同样,您对注释的需求会随着情况的不同而变化。
It's simple and allows you to do copy/paste to comment/uncomment as you would in "normal" coding.
它很简单,允许您像在“正常”编码中那样复制/粘贴到注释/取消注释。
#3
3
That operation is not valid. You can't comment attributes of xml node tags. If you are looking to add some comments to your attributes, place your comment above target node.
该操作无效。不能注释xml节点标记的属性。如果希望向属性添加一些注释,请将注释放在目标节点之上。
< !-- -- >
is a valid way to put comments inside an xml file, but it should be placed as a xml node, not a "node attribute" (inside another node tag).
< !——>是在xml文件中放置注释的有效方法,但是应该将注释作为xml节点,而不是“节点属性”(在另一个节点标记中)。
Example with HTML:
与HTML示例:
<!-- I can comment before the node -->
<div>This node I want to comment</div>
<!-- I can comment after the node -->
But this is not allowed:
但这是不允许的:
<div <!--attribute="12" --> >
According to W3C documentation
根据W3C文档
Note that comments are markup.
注意注释是标记。
Reference:
参考:
- http://www.functionx.com/xml/Lesson04.htm
- http://www.functionx.com/xml/Lesson04.htm
- https://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.4
- https://www.w3.org/TR/html4/intro/sgmltut.html h-3.2.4
- How to comment HTML tag attribute in HTML source code?
- 如何在HTML源代码中注释HTML标签属性?
#4
2
Sorry, no it is not.
对不起,不是。
From Liam R. E. Quin at w3.org: (Asked if it were possible to comment out attributes if not now then in a future version of XML):
来自w3.org的利亚姆·r·e·奎因(被问及是否有可能在将来的XML版本中注释掉属性):
> > SGML allows this, with e.g. > <sock -- age="19" -- state="clean" -- id="s36" > > <shoe -- id="s12" ></sock> > being the same as > <sock state="clean" id="s12"> > > >
but the use of the same start & end delimiter caused a lot of problems, and we got rid of that feature when we defined XML. I'd wanted to change comment start & end to --* and *-- which would have let us keep the ability to have comments inside tags & declarations, and for a while it was in the XML spec, but I seem to remember it was dropped because of SGML compatibility problems.
但是使用相同的开始和结束分隔符造成了很多问题,我们在定义XML时去掉了这个特性。我本想将注释start & end改为——*和*——这将使我们能够在标记和声明中保留注释,并且在一段时间内注释在XML规范中,但我似乎记得,由于SGML兼容性问题,注释被删除了。
I'm afraid it's no longer possible to change XML in incompatible ways - it has become too pervasive - and we no longer have a Working Group doing active work in XML itself.
恐怕再也不可能以不兼容的方式更改XML了——它已经变得太普遍了——而且我们不再有工作组在XML本身中执行活动工作。
Thank you for writing.
谢谢你的写作。
Liam
利亚姆
#1
30
No, this isn't possible. Comments are not allowed in an XML open tag. Depending on your application, you might get away with "commenting out" the attributes by prefixing their names with "_", or you might not (if the XML is validated against a schema or all attributes are parsed). Because whitespace is allowed, and most editors support line operations, you can "comment" multiple attributes easily this way:
不,这是不可能的。在XML开放标记中不允许注释。根据应用程序的不同,您可以通过在属性名前面加上“_”来“注释掉”属性,也可以不这样做(如果根据模式验证XML或解析所有属性)。由于空格是允许的,并且大多数编辑器都支持行操作,所以您可以通过以下方式轻松“注释”多个属性:
<element
_attr1="value1"
_attr2="value2"
_attr3="value3"
>
But these attributes are still part of the document.
但是这些属性仍然是文档的一部分。
#2
11
The only compliant way is to create a node without the attribute in question. I regularly use this approach:
唯一兼容的方法是创建一个没有问题属性的节点。我经常使用这种方法:
<div>
<!-- This opening div tag replaces the one above.
<div my-attribute="my-value"> -->
div contents here...
</div>
The comment to clarify what the commented-out open tag is depends on your need (co-workers using this code, etc.).
注释来澄清什么是被注释掉的open标记取决于您的需要(同事使用此代码等)。
Then, when you need to shift things around, simply change it to:
然后,当你需要改变事情时,只需将它改为:
<!-- <div>
This opening div tag replaces the one below. -->
<div my-attribute="my-value">
div contents here...
</div>
Again, your need for commenting will change with each case.
同样,您对注释的需求会随着情况的不同而变化。
It's simple and allows you to do copy/paste to comment/uncomment as you would in "normal" coding.
它很简单,允许您像在“正常”编码中那样复制/粘贴到注释/取消注释。
#3
3
That operation is not valid. You can't comment attributes of xml node tags. If you are looking to add some comments to your attributes, place your comment above target node.
该操作无效。不能注释xml节点标记的属性。如果希望向属性添加一些注释,请将注释放在目标节点之上。
< !-- -- >
is a valid way to put comments inside an xml file, but it should be placed as a xml node, not a "node attribute" (inside another node tag).
< !——>是在xml文件中放置注释的有效方法,但是应该将注释作为xml节点,而不是“节点属性”(在另一个节点标记中)。
Example with HTML:
与HTML示例:
<!-- I can comment before the node -->
<div>This node I want to comment</div>
<!-- I can comment after the node -->
But this is not allowed:
但这是不允许的:
<div <!--attribute="12" --> >
According to W3C documentation
根据W3C文档
Note that comments are markup.
注意注释是标记。
Reference:
参考:
- http://www.functionx.com/xml/Lesson04.htm
- http://www.functionx.com/xml/Lesson04.htm
- https://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.4
- https://www.w3.org/TR/html4/intro/sgmltut.html h-3.2.4
- How to comment HTML tag attribute in HTML source code?
- 如何在HTML源代码中注释HTML标签属性?
#4
2
Sorry, no it is not.
对不起,不是。
From Liam R. E. Quin at w3.org: (Asked if it were possible to comment out attributes if not now then in a future version of XML):
来自w3.org的利亚姆·r·e·奎因(被问及是否有可能在将来的XML版本中注释掉属性):
> > SGML allows this, with e.g. > <sock -- age="19" -- state="clean" -- id="s36" > > <shoe -- id="s12" ></sock> > being the same as > <sock state="clean" id="s12"> > > >
but the use of the same start & end delimiter caused a lot of problems, and we got rid of that feature when we defined XML. I'd wanted to change comment start & end to --* and *-- which would have let us keep the ability to have comments inside tags & declarations, and for a while it was in the XML spec, but I seem to remember it was dropped because of SGML compatibility problems.
但是使用相同的开始和结束分隔符造成了很多问题,我们在定义XML时去掉了这个特性。我本想将注释start & end改为——*和*——这将使我们能够在标记和声明中保留注释,并且在一段时间内注释在XML规范中,但我似乎记得,由于SGML兼容性问题,注释被删除了。
I'm afraid it's no longer possible to change XML in incompatible ways - it has become too pervasive - and we no longer have a Working Group doing active work in XML itself.
恐怕再也不可能以不兼容的方式更改XML了——它已经变得太普遍了——而且我们不再有工作组在XML本身中执行活动工作。
Thank you for writing.
谢谢你的写作。
Liam
利亚姆