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

开发者活动

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

读取和反序列化 XML 文件

The following example explains how to use activities such as Deserialize XML, Execute XPath, Get XML Nodes, or Get XML Node Attributes for reading, deserializing, accessing, and displaying various information about an XML file. You can find these activities in the UiPath.WebAPI.Activities package.

备注:

Download and extract the archive with the project in this example and copy the file daily_usd.xml to your project folder.

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

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

      变量名称变量类型默认值
      xml字符串
      xmlDeserializedXDocument
      xml_xpath_result对象
      xmlNodesIEnumerable
      xmlAttributesIEnumerable
      allExchRates字符串
  3. Add a Read Text File activity inside the Sequence.
    • Add the expression "daily_usd.xml" in the File Name field.
    • In the Properties panel, add the variable xml in the Content field.
  4. Add a Deserialize XML activity after the Read Text File activity.
    • Add the variable xml in the XML String field.
    • In the Properties panel, add the variable xmlDeserialized in the XMLDocument.
  5. Add an Execute XPath activity after the Deserialize XML activity.
    • Add the variable xmlDeserialized in the Existing XML field.
    • Add the expression "string(/channel/lastBuildDate)" in the XPath Expression field.
    • In the Properties panel, add the variable xml_xpath_result in the Result field.
  6. Add a Message Box activity after the Execute XPath activity.
    • 在“文本”字段中添加表达式 "Exchange rates for " + xml_xpath_result.ToString
  7. Add a Get XML Nodes activity after the Message Box activity.
    • Add the variable xmlDeserialized in the ExistingXML field.
    • In the Properties panel, add the variable xmlNodes in the XMLNodes field.
  8. Add a Get XML Node Attributes activity after the Get XML Nodes activity.
    • Add the expression xmlNodes(0) in the Existing XML Node field.
    • In the Properties panel, add the variable xmlAttributes in the Attributes field.
  9. Add a Message Box activity after the Get XML Node Attributes activity.
    • 在“文本”字段中添加表达式 xmlAttributes(0).Name.Tostring + ": " + xmlAttributes(0).Value.Tostring
  10. Add an Assign activity after the Message Box activity.
    • 在“收件人”字段中添加“allExchRates”变量。
    • 在“值”字段添加表达式 "Exhange Rates" + System.Environment.NewLine
  11. Add a For Each activity after the Assign activity.
    • Add the expression xmlDeserialized.Element("channel").Elements("item") in the Values field.
    • In the Properties panel, select the System.Xml.Linq.XElement option from the TypeArgument drop-down list.
  12. Add an Assign activity inside the Sequence container of the For Each activity.
    • 在“收件人”字段中添加“allExchRates”变量。
    • Add the following expression in the Value field: `allExchRates + System.Environment.NewLine + "1 " + item.Element("baseName").Value.ToString + " = " + item.Element("exchangeRate").Value.ToString
      • " " + item.Element("targetName").Value.ToString`.
  13. Add a Message Box activity after the For Each activity.
    • 在“文本”字段中添加“allExchRates”变量。

      文档图像

  14. 运行流程。 系统将读取、反序列化和访问 XML 文件。 系统将显示几个消息框,其中包含从文件中提取的信息。

您可在此处下载示例。

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新