- 概述
- 加密
- 数据库
- Java
- Python
- 网页 API
开发者活动
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”文档,检索各个节点并写入每个节点的属性和值。
此自动化流程的构建方法如下:
-
打开 Studio ,创建一个新“流程”。
备注:Make sure to place the
.xmlfile inside the project folder. For this example we used theXMLfiles.txt. -
Drag a Sequence to the Workflow Designer.
-
创建以下变量:
变量名称 变量类型 默认值 XMLString字符串 XMLNodesIEnumerable<XNode> XMLDocumentXDocument
-
-
Drag a Read Text File activity inside the sequence container.
- In the Properties panel, add the name
Read XML filein the DisplayName field. - Add the value
"XMLfiles.txt"in the FileName field. - Add the variable
XMLStringin the Content field.
- In the Properties panel, add the name
-
Drag a Deserialize XML activity under the Read Text File activity.
- 在“属性”面板中,向“XML 字符串”字段添加“
XMLString”变量,并向“XML 文档”字段添加“XMLDocument”变量。
- 在“属性”面板中,向“XML 字符串”字段添加“
-
在“反序列化 XML”活动之后放置“获取 XML 节点”活动。
- 在“属性”面板中,向“现有 XML”字段添加“
XMLDocument”变量,并向“XML 节点”字段添加“XMLNodes”变量。
- 在“属性”面板中,向“现有 XML”字段添加“
-
将“遍历循环”活动拖动至“获取 XML 节点”活动之后。
- 在“项目”字段中添加
node值,并在“值”字段中添加变量XMLNodes。 - 从“类型参数”下拉列表中选择
System.Xml.Linq.XNode选项。
- 在“项目”字段中添加
-
Select the Body of the For Each activity and create a new variable:
变量名称 变量类型 默认值 XMLAttributesIEnumerable<XAttribute> -
Add a Write Line activity inside the Body container.
- 在“文本”字段中添加表达式
node.XPathSelectElement("author").ToString。此表达式从.xml页面中选择作者的姓名,并将其写入“输出”面板中。
- 在“文本”字段中添加表达式
-
在“写入行”活动之后放置“获取 XML 节点属性”活动。
- 在“属性”面板中,向“现有 XML 节点”字段中添加值“
node”,并向“XML 属性”字段添加“XMLAttributes”变量。
- 在“属性”面板中,向“现有 XML 节点”字段中添加值“
-
将“遍历循环”活动拖动至“获取 XML 节点属性”活动之后。
- 如要打开活动,请双击。
- 在“项目”字段中添加
attribute值,并在“值”字段中添加变量XMLAttributes。 - 在“属性”面板中,从“目标”下拉列表中选择
System.Xml.Linq.XAttribute选项。
-
Select the Body of the For Each activity.
-
Drag a Write Line activity inside the Body container.
- 在“文本”字段中添加表达式
attribute.Value。
- 在“文本”字段中添加表达式
-
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.
您可在此处下载示例。