Stream Attributes

本文详细介绍了XML流中的关键属性,包括'to'、'from'、'id'、'xml:lang'和'version'等,阐述了这些属性的作用及使用规范。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Stream Attributes

The attributes of the stream element are as follows:
对stream元素的属性描述如下:

  • to -- The 'to' attribute SHOULD be used only in the XML stream header from the initiating entity to the receiving entity, and MUST be set to a hostname serviced by the receiving entity. There SHOULD NOT be a 'to' attribute set in the XML stream header by which the receiving entity replies to the initiating entity; however, if a 'to' attribute is included, it SHOULD be silently ignored by the initiating entity.
  • to -- "to"这个属性只应该出现在发起方至接收方的XML流的格式头中,必须为接收方所提供服务的主机名。该属性不应该出现在接收方返回给发起方的XML流的格式头中,然而如果出现的话就应该忽略。
  • from -- The 'from' attribute SHOULD be used only in the XML stream header from the receiving entity to the initiating entity, and MUST be set to a hostname serviced by the receiving entity that is granting access to the initiating entity. There SHOULD NOT be a 'from' attribute on the XML stream header sent from the initiating entity to the receiving entity; however, if a 'from' attribute is included, it SHOULD be silently ignored by the receiving entity.
  • from -- "from"这个属性只应该出现在接收方至发起方的XML流的格式头中,必须为接收方提供给发起方接入服务的主机名。该属性不应该出现在发送方至接收方的XML流的格式头中,然而如果出现的话就应该忽略。
  • id -- The 'id' attribute SHOULD be used only in the XML stream header from the receiving entity to the initiating entity. This attribute is a unique identifier created by the receiving entity to function as a session key for the initiating entity's streams with the receiving entity, and MUST be unique within the receiving application (normally a server). Note well that the stream ID may be security-critical and therefore MUST be both unpredictable and nonrepeating (see [RANDOM]Eastlake, D., Crocker, S. and J. Schiller, Randomness Recommendations for Security, December 1994. for recommendations regarding randomness for security purposes). There SHOULD NOT be an 'id' attribute on the XML stream header sent from the initiating entity to the receiving entity; however, if an 'id' attribute is included, it SHOULD be silently ignored by the receiving entity.
  • id -- "id"这个属性只应该出现在接收方返回给发起方的XML流的格式头中。该属性是由接收方用作标识发起方会话而创建的一个唯一的标识符,
    将仅在从"receiving entity"到initiating entity的 XML stream头中使用。这个属性是一个唯一的标识符,它由"receiving entity"创建的,用来作为接收 实体与initiating entity的会话key,它在接收应用程序(通常是一个服务器)中 必须是唯一的。 必须设置一个主机名为"receiving entity"使用。注意 流 ID是临 界安全的,因此它必须是不可预料和不重复的( 见[RANDOM])。在从初 始化实体到"receiving entity"的XML stream头中没有 "id"属性; 可是,如果有一 个"id"属性,它将被"receiving entity"悄悄忽略。
  • xml:lang -- An 'xml:lang' attribute (as defined in Section 2.12 of [XML]Bray, T., Paoli, J., Sperberg-McQueen, C. and E. Maler, Extensible Markup Language (XML) 1.0 (2nd ed), October 2000.) SHOULD be included by the initiating entity on the header for the initial stream to specify the default language of any human-readable XML character data it sends over that stream. If the attribute is included, the receiving entity SHOULD remember that value as the default for both the initial stream and the response stream; if the attribute is not included, the receiving entity SHOULD use a configurable default value for both streams, which it MUST communicate in the header for the response stream. For all stanzas sent over the initial stream, if the initiating entity does not include an 'xml:lang' attribute, the receiving entity SHOULD apply the default value; if the initiating entity does include an 'xml:lang' attribute, the receiving entity MUST NOT modify or delete it (see also xml:langxml:lang). The value of the 'xml:lang' attribute MUST be an NMTOKEN (as defined in Section 2.3 of [XML]Bray, T., Paoli, J., Sperberg-McQueen, C. and E. Maler, Extensible Markup Language (XML) 1.0 (2nd ed), October 2000.) and MUST conform to the format defined in RFC 3066Alvestrand, H., Tags for the Identification of Languages, January 2001.[LANGTAGS].
  • xml:lang -- 在initiating entity的 XML stream头中含有一个"xml:lang"属性,为 初始化流用来指定在流中发送的可供人阅读的 XML 字符的缺省语言. 如果包含 这个属性,"receiving entity"将记住这个值作为 "initial stream " 和 "response stream" 两者的缺省值。如果不包含这个属性,"receiving entity"将使用配置值作为两个流的语 言属性缺省值,它必须放在"response stream"头中。对于在"initial stream" 上发送的所有 "XML stanza",如果"initial entity"不包含"xml:log"属性, "receiving entity"将使用缺省值来处理它;如果"initial entity"包含"xml:log"属 性, "receiving entity"必须不能更改和删除它( 见第9.1.5节)."xml:lang"属性值必 须是一个"NMTOKEN"( 见第2.3节) ,必须符合 RFC 3006[LANGTAGS]定义的格 式。
  • version -- The presence of the version attribute set to a value of at least "1.0" signals support for the stream-related protocols (including stream features) defined in this specification. Detailed rules regarding the generation and handling of this attribute are defined below.
  • version -- "presence"的"version"属性值至少为"1.0",支持的相关协议的 Saint-Andre, Ed. Standards Track [Page 11]

黑体关键字参照RFC2119翻译如下:
必须must)、不能must not)、必需的required)、shall)、将不shall not)、应该should)、不应该should not)、建议recommended)、可能may)、和可选的optional

### 使用 Java 8 Stream API 将 `List` 转换为 `Map` 在 Java 8 中,可以利用 Stream API 的强大功能轻松地将 `List` 对象转换为 `Map`。具体实现方式如下: 对于给定的 `List<User>` 列表,可以通过调用 `.stream()` 方法创建流,并使用 `Collectors.toMap()` 来收集结果到一个新的 `Map<Integer, User>` 映射中。 ```java import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class Example { public static void main(String[] args) { List<User> userList = getUserList(); // 将 List<User> 转换为 Map<Integer, User> Map<Integer, User> idAndUserMap = userList.stream() .collect(Collectors.toMap(User::getId, Function.identity())); System.out.println(idAndUserMap); } } ``` 这段代码展示了如何通过指定键提取器 (`User::getId`) 和值提取器 (`Function.identity()`) 完成转换操作[^1]。 当处理更复杂的场景时,比如需要定义自定义冲突解决策略的情况,则可以在第三个参数位置提供一个合并函数来决定遇到重复键时的行为: ```java // 处理可能存在的重复 key 情况下的逻辑 Map<String, String> userMapWithMergeLogic = userList.stream() .collect(Collectors.toMap( User::getUserId, User::getUserName, (existingValue, newValue) -> existingValue // 或者其他业务逻辑 )); ``` 此片段说明了如果存在相同 userId 的情况下保留旧值的方式[^4]。 另外,在某些特殊需求下还可以构建嵌套映射结构,例如从列表项生成多级关联的数据集: ```java // 创建嵌套映射的例子 Map<String, Map<String, String>> nestedMap = list.stream() .collect(Collectors.toMap( Item::getName, item -> item.getAttributes(), (existing, replacement) -> existing)); ``` 这里展示的是基于项目名称建立外层 map 关系的同时,内部存储由 getAttributes 返回的具体属性集合形成内层 map 结构[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值