无法分配给非参考值
我有一个奇怪的问题,我有一个 XMLList,其元素的属性位置从 0 到 x。当我想通过以下语句将文本添加到该 XMLList 的元素时,我收到一条错误消息:
textElements.(@position == columnIndex) = "anyString";
1050:无法分配给非参考值。
这里有什么问题吗?
谢谢 马库斯
I have a strange problem, I have a XMLList with elements who have the attribute position from 0 to x. When I want to add text to a element of that XMLList by the following statement, I get a error message:
textElements.(@position == columnIndex) = "anyString";
1050: Cannot assign to a non-reference value.
What is wrong here?
Thanks
Markus
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
invertedSpear 在答案中使用 [0] 实际上并不是引用 XMLList 索引,而是指示要访问所选节点的子节点的位置。为了进行比较,
这将执行与 invertedSpear 的答案相同的操作,但会将子节点添加到所选节点,而不是直接通过索引访问子节点。节点(如果存在)将始终具有索引为 0 的可用子节点,在这种情况下,它指的是节点本身的值。
请考虑以下事项:
第一个可以工作,如图所示。第二个也可以工作,如图所示。然而,第三个将会失败,因为位置 == 3 的节点在索引 1 处没有子节点。请注意,这将起作用...
The use of [0] in the answer by invertedSpear is not actually referencing the XMLList index, it is indicating the position of the child to access of the selected node. For comparison
This will do the same thing as invertedSpear's answer, but will add a child to the selected node, rather than accessing the child node directly by index. A node, if it exists, will always have the child indexed at 0 available, in this case it refers to the value of the node itself.
Consider the following:
The first one will work, as shown. The second one will also work, as shown. The third, however, will fail because the node with position == 3 does not have a child at index 1. Notice that this will work...
在处理 XMLList 时,您必须更加具体一些。实际上,您必须告诉它您想要更改列表中的哪个项目,即使您将其过滤到只有 1 个。这应该可以为您完成:
you have to be a little more specific when dealing with XMLLists. You actually have to tell it which item in the list you are wanting to change, even when you filter it down to only 1. This should do it for you: