UiPath Documentation
activities
latest
false
重要 :
请注意,此内容已使用机器翻译进行了部分本地化。 新发布内容的本地化可能需要 1-2 周的时间才能完成。

开发者活动

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

检测并分析 XML 文件

以下示例说明了如何使用“反序列化 XML”“执行 XPath”等活动来反序列化和分析 XML 文件。您可以在“UiPath.WebAPI.Activities ”包中找到这些活动。

备注:

Download and extract the archive with the project in this example and copy the folder MissingScreenshotSampleProject-ForTestPurposes to your project folder.

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

  1. 打开 Studio ,创建一个新“流程”
  2. 将“序列”容器拖动至“工作流设计器”
    • 创建以下变量:

      变量名称变量类型默认值
      SelectedProjectPath字符串
      WorkflowXMLString字符串
      WorkflowXMLXDocument
      ScreenshotAttributes对象
  3. Add a Select Folder activity inside the Sequence.
    • In the Properties panel, add the variable SelectedProjectPath in the SelectedFolder field.
  4. “遍历循环”活动添加到“选择文件夹”活动之后。
    • Add the value WorkflowFile in the ForEach field.
    • Add the expression Directory.GetFiles(SelectedProjectPath, "*.xaml", SearchOption.AllDirectories) in the Values field.
  5. Add a Read Text File in the Body container of the For Each activity.
    • Add the value WorkflowFile in the FileName field.
    • In the Properties panel, add the variable WorkflowXMLString in the Content field.
  6. “反序列化 XML”活动添加到“读取文本文件”之后。
    • Add the variable WorkflowXMLString in the XMLString field.
    • In the Properties panel, add the value WorkflowXML in the XMLDocument field.
  7. “执行 XPath”活动添加到“反序列化 XML”活动之后。
    • Add the value WorkflowXML in the Existing XML field.
    • Add the expression "//@InformativeScreenshot" in the XPath Expression field.
    • In the Properties panel, add the variable ScreenshotAttributes in the Result field.
  8. “遍历循环”活动添加到“执行 XPath”活动之后。
    • Add the value Attribute in the ForEach field.

    • Add the expression CType(ScreenshotAttributes, IEnumerable).Cast(Of XAttribute) in the Values field.

    • Select the Body container of the activity and create the following variable:

      变量名称变量类型默认值
      ScreenshotFileExists布尔值
  9. Add a Log Message activity inside the Body container of the For Each activity.
    • 在“行”字段中添加表达式“"Looking for: " + SelectedProjectPath + "\.screenshots\" + Attribute.Value + ".png"”。
  10. “存在路径”活动添加到“日志消息”活动之后。
    • Select the File option from the Path File drop-down list.
    • Add the expression SelectedProjectPath + "\.screenshots\" + Attribute.Value + ".png" in the XPath Expression field.
  11. 将“ IF 条件”活动添加到“存在路径”活动之后。
    • 在“条件”字段中添加表达式“Not ScreenshotFileExists”。
  12. Add a Log Message activity inside the Then field of the If activity.
    • Select the Warn option from the Level drop-down list.

    • 在“行”字段中添加表达式“String.Format("Could not find the screenshot file {0}.png referenced by file {1}", Attribute.Value, WorkflowFile)”。

  13. 运行流程。出现提示时,选择“MissingScreenshotSampleProject-ForTestPurposes ”文件夹。系统将读取文件夹中的 XML 工作流文件并对其进行反序列化。有关 XAML 中引用的屏幕截图的信息用于识别和记录在文件夹中找到和丢失的屏幕截图。

您可在此处下载示例。

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新