首页 > 解决方案 > 使用 UIPATH 解析 XML 并将值转储到 Excel

问题描述

我想转储只有宝马汽车的数据才能脱颖而出。我确实有数千个 XML 文件,并且许多条目会有所不同(在本例中为 3,它可以从 0 到 5)。

考虑到这种情况,我必须在 UIPATH 中增加计数器或事务项。但首先我想将这个 XML 文件的数据转储到 excel 中,我希望在附加的图像中给出输出

    <country>
                <state>Texas</state>
                    <cars>        
                                 <brand>BMW</brand>
                                 <model>X1</model>
                                 <unit>210000</unit>        
                    </cars>
                    <cars>        
                                <brand>BMW</brand>
                                <model>X6</model>
                                <unit>210000</unit>     
                    </cars>
                    <cars>        
                                <brand>BMW</brand>
                                <model>X7</model>
                                 <unit>210000</unit>        
                    </cars>
                    <cars>        
                                 <brand>Ford</brand>
                                 <model>mustang</model>
                                 <unit>319000</unit>        
                    </cars>
                    <cars>        
                                 <brand>Volvo</brand>
                                <model>XC90</model>
                                 <unit>91100</unit>     
                    </cars> 
    </country>

**输出 - **

在此处输入图像描述

标签: xmlxml-parsingxml-deserializationuipath

解决方案


好吧,有几种可能的方法,您选择哪一种取决于您对 .NET 的熟悉程度(使用XDocument类,此处的 UiPath KB 中有更多详细信息)。

如果您希望避免这种情况,您可以尝试仅使用该Execute XPath函数的以下序列:

 1. For each XML file
 2. ... Get number of BMWs: count(//cars/brand[text()='BMW'])
 3. ... Loop that amount of times
 4. ... ... Get each individual value for that car: string(//cars[brand[text()='BMW']][i]/model)
    ... ... ... (replace the i for the loop number)
 5. ... ... Write that to Excel
 6. ... ... Repeat the previous command also for unit

推荐阅读