'Join all p tags XPATH Power Automate
Been struggling with a flow to add rows in excel from html table.
I've followed this guide from youtube Youtube and it works with the first p tag But i want to join all ptags to same string.
This will iterate through all items and retrieve the first p1, next iteration p2 and so on.. "xpath(xml(outputs('XMLHTML')), concat('//table[.1]//tr[.2]//td[.1]//p[',item(),']//text()'))?[0]"
But in my case it looks like this

<p class="MsoNormal"> <span lang="EN-US" style="font-size:11.0pt; color:black; border:none windowtext 1.0pt; padding:0cm">GLU900 L700/800/1800</span> <span lang="EN-US" style="font-size:11.0pt; border:none windowtext 1.0pt; padding:0cm">/2100/2600/2602 ;</span> <span lang="EN-US" style="font-size:11.0pt; color:black; border:none windowtext 1.0pt; padding:0cm">5G ;</span> <span lang="EN-US" style="font-size:11.0pt; border:none windowtext 1.0pt; padding:0cm">3<span style="color:black"> sector</span></span> </p>
"//table[.1]//tr2//td3//p[.1]//text()"
And i will only retrieve the first item. I want to join all 5 element to same string and then iterate through the next set of p tags
this is what i've found, but I dont know how to iterate through this when its not ending with a text() function in xpath xpath(xml(outputs('XMLHTML')), 'string(//table1//tr2//td3//p[',item(),'])')?[0]
Error Message
The execution of template action 'Select' failed: The evaluation of 'query' action 'where' expression '{ "FuncID": "@xpath(xml(outputs('XMLHTML')), concat('//table1//tr2//td1//p[',item(),']//text()'))?[0]", "SiteName": "@xpath(xml(outputs('XMLHTML')), concat('//table1//tr2//td2//p[',item(),']//text()'))?[0]", "Technology": "@xpath(xml(outputs('XMLHTML')), 'string(//table1//tr2//td3//p[',item(),'])')?[0]", "Comment": "@xpath(xml(outputs('XMLHTML')), concat('//table1//tr2//td4//p[',item(),']//text()'))?[0]" }' failed: 'The template language function 'xpath' expects two parameters: an XML object and an XPath expression. The function was invoked with '4' parameter(s). Please see https://aka.ms/logicexpressions#xpath for usage details.'.
So, at the end How do i concatenate all 5 elements in list of p-tags to one line and how do i iterate through the elements in power automate??
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" width="939"
style="width:703.95pt; margin-left:.1pt; border-collapse:collapse">
<tbody>
<tr style="height:15.75pt">
<td width="54" nowrap=""
style="width:40.8pt; border:solid windowtext 1.0pt; padding:0cm 3.5pt 0cm 3.5pt; height:15.75pt">
<p class="MsoNormal"><b><span
style="font-size:11.0pt; color:black; border:none windowtext 1.0pt; padding:0cm">FuncID</span></b>
</p>
</td>
<td width="197" nowrap=""
style="width:147.45pt; border:solid windowtext 1.0pt; border-left:none; padding:0cm 3.5pt 0cm 3.5pt; height:15.75pt">
<p class="MsoNormal"><b><span
style="font-size:11.0pt; color:black; border:none windowtext 1.0pt; padding:0cm">SiteName</span></b>
</p>
</td>
<td width="485" nowrap=""
style="width:364.1pt; border:solid windowtext 1.0pt; border-left:none; padding:0cm 3.5pt 0cm 3.5pt; height:15.75pt">
<p class="MsoNormal"><b><span
style="font-size:11.0pt; color:black; border:none windowtext 1.0pt; padding:0cm">Technology</span></b>
</p>
</td>
<td width="202" nowrap=""
style="width:151.6pt; border:solid windowtext 1.0pt; border-left:none; padding:0cm 3.5pt 0cm 3.5pt; height:15.75pt">
<p class="MsoNormal"><b><span style="font-size:11.0pt; color:black">Comments</span></b></p>
</td>
</tr>
<tr style="height:43.4pt">
<td width="54" nowrap=""
style="width:40.8pt; border:solid windowtext 1.0pt; border-top:none; padding:0cm 3.5pt 0cm 3.5pt; height:43.4pt">
<p class="MsoNormal"><span style="font-size:11.0pt">T223566</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">T335125</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">T311000</span></p>
</td>
<td width="197" nowrap=""
style="width:147.45pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 3.5pt 0cm 3.5pt; height:43.4pt">
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">Testing1 test1 test1</span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">Testing2 test2 test2</span></p>
<p class="MsoNormal"><span lang="EN-US">Testing 3 test3 test3</span></p>
</td>
<td width="485" nowrap=""
style="width:364.1pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 3.5pt 0cm 3.5pt; height:43.4pt">
<p class="MsoNormal"><span lang="EN-US">GLU900 L700/800/1800/2100/2600/2602 5G 4 Sec</span>tor<span
lang="EN-US"></span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="EN-US"
style="font-size:11.0pt; color:black; border:none windowtext 1.0pt; padding:0cm">GLU900
L700/800/1800</span><span lang="EN-US"
style="font-size:11.0pt; border:none windowtext 1.0pt; padding:0cm">/2100/2600/2602
</span><span lang="EN-US"
style="font-size:11.0pt; color:black; border:none windowtext 1.0pt; padding:0cm">5G
</span><span lang="EN-US"
style="font-size:11.0pt; border:none windowtext 1.0pt; padding:0cm">5</span><span lang="EN-US"
style="font-size:11.0pt; color:black; border:none windowtext 1.0pt; padding:0cm"> sector</span>
</p>
</td>
<td width="202" nowrap=""
style="width:151.6pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 3.5pt 0cm 3.5pt; height:43.4pt">
<p class="MsoNormal"><span lang="EN-US"
style="font-size:11.0pt; border:none windowtext 1.0pt; padding:0cm"> </span></p>
<p class="MsoNormal"><span lang="EN-US"
style="font-size:11.0pt; color:black; border:none windowtext 1.0pt; padding:0cm">5G will be
activated tomorrow</span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">3-D</span></p>
</td>
</tr>
</tbody>
BR Erik
Update Flow
Solution 1:[1]
Firstly, to make it work, I had to remove the data from your HTML, it didn't like it. See how you go though.
There are a few options for your XPath query, it all depends on the specifics of what you want to achieve. Try these for example ...
//p/span/text()
T223566
T335125
T311000
Testing1 test1 test1
Testing2 test2 test2
Testing 3 test3 test3
GLU900 L700/800/1800/2100/2600/2602 5G 4 Sec
//p/descendant::*/text()
FuncID
SiteName
Technology
Comments
T223566
T335125
T311000
Testing1 test1 test1
Testing2 test2 test2
Testing 3 test3 test3
GLU900 L700/800/1800/2100/2600/2602 5G 4 Sec
Depending on which one you choose, they will return an array of values and by the looks if it, it will ignore all of the blank rows.
I tested with the second XPath query in my flow which yielded the following result ...
This was the step after initializing a variable which contained your HTML data (again, removing the values though) ...
xpath(xml(variables('XML')), '//p/descendant::*/text()')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Skin |







