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

开发者活动
上次更新日期 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.
此自动化流程的构建方法如下:
- 打开 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
- Add a Deserialize XML activity after the Read Text File activity.
- Add the variable
xmlin the XML String field. - In the Properties panel, add the variable
xmlDeserializedin the XMLDocument.
- Add the variable
- Add an Execute XPath activity after the Deserialize XML activity.
- 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
- Add a Message Box activity after the Execute XPath activity.
- 在“文本”字段中添加表达式
"Exchange rates for " + xml_xpath_result.ToString。
- 在“文本”字段中添加表达式
- Add a Get XML Nodes activity after the Message Box activity.
- Add the variable
xmlDeserializedin the ExistingXML field. - In the Properties panel, add the variable
xmlNodesin the XMLNodes field.
- Add the variable
- 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
xmlAttributesin the Attributes field.
- Add the expression
- Add a Message Box activity after the Get XML Node Attributes activity.
- 在“文本”字段中添加表达式
xmlAttributes(0).Name.Tostring + ": " + xmlAttributes(0).Value.Tostring。
- 在“文本”字段中添加表达式
- Add an Assign activity after the Message Box activity.
- 在“收件人”字段中添加“
allExchRates”变量。 - 在“值”字段添加表达式
"Exhange Rates" + System.Environment.NewLine。
- 在“收件人”字段中添加“
- 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.
- Add the expression
- 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`.
- 在“收件人”字段中添加“
- Add a Message Box activity after the For Each activity.
-
在“文本”字段中添加“
allExchRates”变量。
-
- 运行流程。 系统将读取、反序列化和访问 XML 文件。 系统将显示几个消息框,其中包含从文件中提取的信息。
您可在此处下载示例。