UiPath Documentation
activities
latest
false

开发者活动

上次更新日期 2026年4月21日

获取 XML 节点属性

UiPath.WebAPI.Activities.GetXMLNodeAttributes

描述

检索 XML 节点的属性。

项目兼容性

Windows - 旧版 | Windows | 跨平台

跨平台配置

  • “现有 XML 节点” - 要检索其属性的 XML 节点。此字段仅支持XNode变量。有关XNode对象的更多信息,请转到此处
高级选项

输出

  • “属性” - 包含检索到的 XML 节点属性的IEnumerable<XAttribute>变量。有关XAttribute对象的更多信息,请转到此处

Windows - 旧版 Windows 配置

属性面板

输入

  • “现有 XML 节点” - 要检索其属性的 XML 节点。此字段仅支持XNode变量。有关XNode对象的更多信息,请转到此处

输出

  • “属性” - 包含检索到的 XML 节点属性的IEnumerable<XAttribute>变量。有关XAttribute对象的更多信息,请转到此处

其他

  • “私有”- 选中后将不再以“Verbose”级别记录变量和参数的值。

常见

  • “显示名称”- 活动的显示名称。

使用“获取 XML 节点属性”活动的示例

“获取 XML 节点属性”活动用于处理 .xml 文件。

为举例说明如何使用此活动,我们创建了一个示例,用于读取 .xml 文件,将其转换为“XML”文档,检索各个节点并写入每个节点的属性和值。

此自动化流程的构建方法如下:

  1. 打开 Studio ,创建一个新“流程”

    备注:

    Make sure to place the .xml file inside the project folder. For this example we used the XMLfiles.txt.

  2. Drag a Sequence to the Workflow Designer.

    • 创建以下变量:

      变量名称变量类型默认值
      XMLString字符串
      XMLNodesIEnumerable<XNode>
      XMLDocumentXDocument
  3. Drag a Read Text File activity inside the sequence container.

    • In the Properties panel, add the name Read XML file in the DisplayName field.
    • Add the value "XMLfiles.txt" in the FileName field.
    • Add the variable XMLString in the Content field.
  4. Drag a Deserialize XML activity under the Read Text File activity.

    • 在“属性”面板中,向“XML 字符串”字段添加“XMLString”变量,并向“XML 文档”字段添加“XMLDocument”变量。
  5. “反序列化 XML”活动之后放置“获取 XML 节点”活动。

    • 在“属性”面板中,向“现有 XML”字段添加“XMLDocument”变量,并向“XML 节点”字段添加“XMLNodes”变量。
  6. “遍历循环”活动拖动至“获取 XML 节点”活动之后。

    • 在“项目”字段中添加 node 值,并在“值”字段中添加变量 XMLNodes
    • 从“类型参数”下拉列表中选择 System.Xml.Linq.XNode 选项。
  7. Select the Body of the For Each activity and create a new variable:

    变量名称变量类型默认值
    XMLAttributesIEnumerable<XAttribute>
  8. Add a Write Line activity inside the Body container.

    • 在“文本”字段中添加表达式 node.XPathSelectElement("author").ToString。此表达式从 .xml 页面中选择作者的姓名,并将其写入“输出”面板中。
  9. “写入行”活动之后放置“获取 XML 节点属性”活动。

    • 在“属性”面板中,向“现有 XML 节点”字段中添加值“node”,并向“XML 属性”字段添加“XMLAttributes”变量。
  10. “遍历循环”活动拖动至“获取 XML 节点属性”活动之后。

    • 如要打开活动,请双击。
    • 在“项目”字段中添加 attribute 值,并在“值”字段中添加变量 XMLAttributes
    • 在“属性”面板中,从“目标”下拉列表中选择 System.Xml.Linq.XAttribute 选项。
  11. Select the Body of the For Each activity.

  12. Drag a Write Line activity inside the Body container.

    • 在“文本”字段中添加表达式 attribute.Value
  13. Run the process. The robot extracts an attribute and a value from the nodes, in this case, the name of the author and the book id, and displays them in the Output panel.

您可在此处下载示例。

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新