activities
latest
false
- 概述
- 加密
- 数据库
- Java
- Python
- 网页 API
重要 :
请注意,此内容已使用机器翻译进行了部分本地化。
新发布内容的本地化可能需要 1-2 周的时间才能完成。

开发者活动
上次更新日期 2026年4月21日
读取和反序列化 XML 文件
以下示例说明了如何使用“反序列化 XML” 、 “执行 XPath” 、 “获取 XML 节点”或“获取 XML 节点属性”等活动来读取、反序列化、访问和显示有关 XML 文件的各种信息。您可以在“UiPath.WebAPI.Activities ”包中找到这些活动。
备注:
Download and extract the archive with the project in this example and copy the file daily_usd.xml to your project folder.
此自动化流程的构建方法如下:
- 打开 Studio ,创建一个新“流程”。
- 将“序列”容器拖动至“工作流设计器”。
-
创建以下变量:
变量名称 变量类型 默认值 xml字符串 xmlDeserializedXDocument xml_xpath_result对象 xmlNodesIEnumerable xmlAttributesIEnumerable allExchRates字符串
-
- 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
xmlin the Content field.
- Add the expression
- 将“反序列化 XML”活动添加到“读取文本文件”活动之后。
- Add the variable
xmlin the XML String field. - In the Properties panel, add the variable
xmlDeserializedin the XMLDocument.
- Add the variable
- 将“执行 XPath”活动添加到“反序列化 XML”活动之后。
- Add the variable
xmlDeserializedin the Existing XML field. - Add the expression
"string(/channel/lastBuildDate)"in the XPath Expression field. - In the Properties panel, add the variable
xml_xpath_resultin the Result field.
- Add the variable
- 在“执行 XPath”活动之后添加“消息框”活动。
- 在“文本”字段中添加表达式
"Exchange rates for " + xml_xpath_result.ToString。
- 在“文本”字段中添加表达式
- 将“获取 XML 节点”活动添加到“消息框”活动之后。
- Add the variable
xmlDeserializedin the ExistingXML field. - In the Properties panel, add the variable
xmlNodesin the XMLNodes field.
- Add the variable
- 将“获取 XML 节点属性”活动添加到“获取 XML 节点”活动之后。
- Add the expression
xmlNodes(0)in the Existing XML Node field. - In the Properties panel, add the variable
xmlAttributesin the Attributes field.
- Add the expression
- 在“获取 XML 节点属性”活动之后添加“消息框”活动。
- 在“文本”字段中添加表达式
xmlAttributes(0).Name.Tostring + ": " + xmlAttributes(0).Value.Tostring。
- 在“文本”字段中添加表达式
- 将“分配”活动添加到“消息框”活动之后。
- 在“收件人”字段中添加“
allExchRates”变量。 - 在“值”字段添加表达式
"Exhange Rates" + System.Environment.NewLine。
- 在“收件人”字段中添加“
- 将“遍历循环”活动添加到“分配”活动之后。
- 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.
- Add the expression
- Add an Assign activity inside the Sequence container of the For Each activity.
- 在“收件人”字段中添加“
allExchRates”变量。 - 在“值”字段中添加以下表达式:`allExchRates + System.Environment.NewLine + "1 " + item.Element("baseName").Value.ToString + " = " + item.Element("exchangeRate").Value。目标字符串
- + item.Element("targetName").Value.ToString`。
- 在“收件人”字段中添加“
- 将“消息框”活动添加到“遍历循环”活动之后。
-
在“文本”字段中添加“
allExchRates”变量。
-
- 运行流程。 系统将读取、反序列化和访问 XML 文件。 系统将显示几个消息框,其中包含从文件中提取的信息。
您可在此处下载示例。